结构体 快速排序的问题
2412 000
2417 2200
2422 000
2427 000
2432 000
2442 000
2447 23120
2437 00.50
2452 000
2457 000
2462 0230
2467 000
2472 000
2484 03330
以上是我要排序的数据,我用一个结构体储存。
struct CableLoss
{
int fre;
double value[10];
};
fre 表示 第一列的频率
value[10]储存后面的数据。
现在要按照fre排序即可。
我的code如下
CableLoss Atten_2G[20];
int cmp( const void *a ,const void *b)
{
return (*(CableLoss *)a).fre > (*(CableLoss *)b).fre ? 1 : -1;
}
qsort(Atten_2G,count_2G,sizeof(Atten_2G[0]),cmp);