fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Cos { short val,num; } Cos;
  5.  
  6. int compare_cos(const void * a, const void * b)
  7. {
  8. short A=(*((Cos**)a))->val,B=(*((Cos**)b))->val;
  9. printf("%hd <> %hd \n",A,B);
  10. return (A<B)-(B<A);
  11. }
  12.  
  13. int main(int argc, char const *argv[])
  14. {
  15. int i;
  16. Cos *tab[10];
  17. for(i=0;i<10; ++i)
  18. {
  19. Cos *c=malloc(sizeof(Cos));
  20. c->val=i+1;
  21. c->num=i+1;
  22. tab[i]=c;
  23. printf("%hd %hd\n",c->val,c->num);
  24. }
  25. printf("\nSORTOWANIE:\n");
  26. qsort(tab,10,sizeof(Cos),compare_cos);
  27. for(i=0;i<10;++i) printf("%hi %hi\n",tab[i]->val,tab[i]->num);
  28. return 0;
  29. }
Success #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

SORTOWANIE:
1 <> 2 
4 <> 5 
3 <> 5 
3 <> 4 
2 <> 5 
2 <> 4 
2 <> 3 
6 <> 7 
9 <> 10 
8 <> 10 
8 <> 9 
7 <> 10 
7 <> 9 
7 <> 8 
5 <> 10 
5 <> 9 
5 <> 8 
5 <> 7 
5 <> 6 
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1