#include <stdio.h>
typedef struct {
int id;
int weight;
int height;
}list;
void swap(list *a,list *b);
int main(void) {
list data[] = {
{1,65,169},
{2,73,170},
{3,59,161},
{4,79,175},
{5,55,168},
};
for(int i=0;i<4;i++){
for(int j=i+1;j<5;j++){
if(data[i].height < data[j].height) {
swap(&data[i],&data[j]);
}
}
}
for(int i=0;i<5;i++){
printf("id: %d, weight: %d, height: %d\n", data
[i
].
id,data
[i
].
weight,data
[i
].
height); }
return 0;
}
void swap(list *a,list *b) {
list w;
w = *a;
*a = *b;
*b = w;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp0eXBlZGVmIHN0cnVjdCB7CglpbnQgaWQ7CglpbnQgd2VpZ2h0OwoJaW50IGhlaWdodDsKfWxpc3Q7Cgp2b2lkIHN3YXAobGlzdCAqYSxsaXN0ICpiKTsKCmludCBtYWluKHZvaWQpIHsKCWxpc3QgZGF0YVtdID0gewoJCXsxLDY1LDE2OX0sCgkJezIsNzMsMTcwfSwKCQl7Myw1OSwxNjF9LAoJCXs0LDc5LDE3NX0sCgkJezUsNTUsMTY4fSwKCX07Cglmb3IoaW50IGk9MDtpPDQ7aSsrKXsKCQlmb3IoaW50IGo9aSsxO2o8NTtqKyspewoJCQlpZihkYXRhW2ldLmhlaWdodCA8IGRhdGFbal0uaGVpZ2h0KSB7CgkJCQlzd2FwKCZkYXRhW2ldLCZkYXRhW2pdKTsKCQkJfQoJCX0KCX0KCQoJCglmb3IoaW50IGk9MDtpPDU7aSsrKXsKCQlwcmludGYoImlkOiAlZCwgd2VpZ2h0OiAlZCwgaGVpZ2h0OiAlZFxuIiwgZGF0YVtpXS5pZCxkYXRhW2ldLndlaWdodCxkYXRhW2ldLmhlaWdodCk7Cgl9CgkKCXJldHVybiAwOwp9Cgp2b2lkIHN3YXAobGlzdCAqYSxsaXN0ICpiKSB7CglsaXN0IHc7Cgl3ID0gKmE7CgkqYSA9ICpiOwoJKmIgPSB3Owp9Cg==
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