fork download
  1. #include <iostream>
  2. #include<stdlib.h>
  3. using namespace std;
  4.  
  5. static int cnt;
  6.  
  7. int compare(const void *a, const void *b)
  8. {
  9. int l = *(int*)a;
  10. int r= *(int*)b;
  11. cout<<"compare "<<l<<" with "<<r<<endl;
  12. return l-r;
  13. }
  14.  
  15. int main() {
  16. // your code goes here
  17. int a[]= {10,9,8,7,6,5};
  18. int size= sizeof(a)/sizeof(a[0]);
  19. int i;
  20. qsort(a,size,sizeof(int),compare);
  21.  
  22. for(i=0;i<6;i++)
  23. cout<<a[i]<<" ";
  24.  
  25. cout<<endl<<cnt<<endl;
  26. return 0;
  27. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
compare 9 with 8
compare 10 with 8
compare 10 with 9
compare 6 with 5
compare 7 with 5
compare 7 with 6
compare 8 with 5
compare 8 with 6
compare 8 with 7
5 6 7 8 9 10 
0