|  | 
|  | 
| вернуться в форум | WA... I may be wrong to pass parameters to the function qsort? #include<stdio.h>#include<stdlib.h>
 int compare(const void *a, const void *b)
 {
 if(*(*(int**)a+1)<*(*(int**)b+1))
 return 1;
 else
 return -1;
 }
 int main()
 {
 int n,i,**arr;
 scanf("%d",&n);
 arr=(int**)calloc(n,sizeof(int*));
 for(i=0;i<n;i++)
 {
 arr[i]=(int*)calloc(2,sizeof(int));
 scanf("%d %d",&arr[i][0],&arr[i][1]);
 }
 qsort(arr,n,4,compare);
 for(i=0;i<n;i++)
 {
 printf("%d %d\n",arr[i][0],arr[i][1]);
 free(arr[i]);
 }
 free(arr);
 return 0;
 }
Re: WA... I may be wrong to pass parameters to the function qsort? Reread the condition.You must output the same results table as bubble sort, but faster.
 Qsort gives other result.
 Test output:    Yuor output:
 3 5         3 5
 26 4        26 4
 22 4        22 4
 16 3        20 3
 20 3        16 3
 1 2        11 2
 11 2        1 2
 7 1        7 1
 
 WA
 
 
 Edited by author 23.07.2013 14:47
 | 
 | 
|