# pointers - 使用qsort对 2D array 进行排序时警告

`warning: initialization discards 'const' qualifier from pointer target type [enabled by default]`

``````
int cmp (const void *pa, const void *pb ) {
const int (*a)[2] = pa;//warning here
const int (*b)[2] = pb;//warning here
if ( (*a)[1] <(*b)[1] ) return 1;
if ( (*a)[1]> (*b)[1] ) return -1;
return 0;
}

``````

``````
int letterCount[26][2] = {{0, 0},{1, 0},{2, 0},{3, 0},{4, 0},{5, 0},{6, 0},{7, 0},{8, 0},{9, 0},{10, 0},{11, 0},{12, 0},{13, 0},{14, 0},{15, 0},{16, 0},{17, 0},{18, 0},{19, 0},{20, 0},{21, 0},{22, 0},{23, 0},{24, 0},{25, 0}};

``````

``````
int cmp (const void *pa, const void *pb )
{
const int *a = pa;
const int *b = pb;
if (a[1] <b[1])
return -1;
return (b[1] <a[1]);
}

``````

``````
#include <time.h>
#include <stdio.h>
void Qsort(int matrix[][2], int lenght)
{
if(!lenght)
return;
int temp = 0, pivot, b = 0, e = lenght - 1, test = 0;
const int MIN =0, MAX = e;
srand(time(NULL));
test = (rand() % (MAX - MIN + 1)) + MIN;
pivot = matrix[test][1];
while(b <e)
{
while(matrix[b][1] <pivot)
b++;
while(matrix[e][1]> pivot)
e--;
temp = matrix[b][1];
matrix[b][1] = matrix[e][1];
matrix[e][1] = temp;
}
Qsort(matrix, b);
Qsort(&(matrix)[b + 1], lenght - 1 - b);

}

``````