桶排序-C-结构体排序

时间:2024-05-25 21:37:14
    struct TS {
int index;
char name[];
}; struct TS b[] = {{,"s5"},{,"s2"},{,"s3"},{,"s1"},{,"s8"}}; struct TS a[];
int i;
int length = sizeof(a) / sizeof (struct TS);
for(i=;i<length;i++){
struct TS tmp = {,""};
a[i] = tmp;
} for (i=; i<; i++) {
int num = b[i].index;
if(a[num].index >= ){
a[num] = b[i];
}else{
struct TS tmp = {,""};
a[num] = tmp;
}
} for (i=; i<; i++) {
if(a[i].index)
printf("%s\n",a[i].name);
}

相关文章