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