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