Sorting a 2 D matrix

Hi ,

I have a 2 D matrix which is a vector <vector> type. I wan to find out the unique rows. To use std::unique the rows have to be sorted. I tried using std::sort with a predicate. But sorting does not work . Could someone help me


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
typedef std::vector<float> Vec_float;
typedef std::vector<Vec_float> matrix_float;



//this function is a predicate for sorting the matrix  and then eliminating duplicates
bool sort_pred (Vec_float i , Vec_float j)
{
    bool val=true;
    for(int it=0;it< i.size();++it)
    {
        if (i[it]!=j[it])
        {
            val=false;
            return(val);
        }
    }
    return val;
}
//this is the actual sorting function 

void vec_vec_sort (matrix_float& ext_met)
{
    std::sort(ext_met.begin(),ext_met.end(),sort_pred);
    //unique function removes consecutive duplicates in a range
    //the return value of unique is
    //A forward iterator pointing to the new end of the sequence, which now does not include the elements that were consecutive duplicates.

    matrix_float::iterator it;
    it=std::unique(ext_met.begin(),ext_met.end());
    //removing unwanted duplicate elements
    ext_met.erase(it,ext_met.end());
}
Topic archived. No new replies allowed.