fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4. int id;
  5. int weight;
  6. int height;
  7. }list;
  8.  
  9. void display(list data[]);
  10. void comparison(list data[], int size);
  11. void swap (list *a,list *b);
  12. int main(void) {
  13. list data[]={
  14. {1,65,160},
  15. {2,73,170},
  16. {3,59,161},
  17. {4,79,175},
  18. {5,55,168}
  19. };
  20.  
  21. comparison(data,5);
  22.  
  23. display(data);
  24. return 0;
  25. }
  26. void display(list d[])
  27. {
  28. for(int i=0;i<5;i++){
  29. printf("%d, %d, %d\n",d[i].id,d[i].weight,d[i].height);
  30. }
  31. }
  32.  
  33. void comparison(list data[],int size){
  34. for(int k=0;k<size-1;k++){
  35. for(int j=k+1;j<size;j++){
  36. if(data[k].height<data[j].height){
  37. swap(&data[k],&data[j]);
  38. }
  39. }
  40. }
  41. }
  42.  
  43. void swap(list *a,list *b){
  44. list w;
  45. w=*a;
  46. *a=*b;
  47. *b=w;
  48. }
  49.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
5, 55, 168
3, 59, 161
1, 65, 160