std::sort for sorting two dimensional array of integers?

Hi, I have code, where I need to sort two dimensional array. I know I can use qsort(), but I would like to try std::sort to do this. Is it even possible to sort 2D array using std::sort?
Here is the code:
1
2
3
4
5
6
7
8
int **array;
int n = 100;
array = (int **)malloc(size * sizeof(int *));
for(int i = 0; i < n; i++)
{
 array[i] = (int *)malloc((3) * sizeof(int));
}
std::sort(array, array+n,cmp_int);


And cmp_int looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
bool cmp_int(const void *a, const void *b)
{
    const int **ia = (const int **)a;
    const int **ib = (const int **)b;
    int i;
    for(i=0; i < 3; i++)
      {
        if(ia[0][i] < ib[0][i]){
          return true;
          }
      }
     return false;
}


When I compile and run the code, SEGMENTATION FAULT occures at comparison of two values, becouse ib[][] is out of range of an array.
Can anyone help me?
thanks
cmp_int should take const int*, not const void*, and the parameters passed to it are not double-pointers, so your double dereference is wrong.

What ordering do you want on a 2D array? Ie, what does it mean to sort a 2D array?
Topic archived. No new replies allowed.