#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct student
{
char name[20];
double score;
} STU, *PSTU; //定义记录类型,及指向记录的指针类型
int compare(const void * s1, const void *s2 )
{
PSTU p1 = (PSTU )s1;
PSTU p2 = (PSTU )s2;
if (p1->score - p2->score >1e-6)
return 1;
else if (p2->score - p1->score > 1e-6)
return -1;
else
return 0;
}
int main(){
STU record[N]={
{"wangfang",98.5},
{"licheng",93},
{"gaohong",97},
{"chengguangnan",91},
{"zhangpengfei",94.5}
};
qsort(record, N, sizeof(STU), compare);
for (int i=0;i<N; i++)
{
printf("%s:\t%5.1lf\n",record[i].name, record[i].score);
}
return 0;
}