Data_Structure/作業/unit0/bowling-struct-sort.c

37 lines
791 B
C
Raw Normal View History

2025-01-20 21:25:33 +08:00
#include <stdio.h>
typedef struct game {
char name[8]; /* <20><><EFBFBD>ɪ̩m<CCA9>W */
int score; /* <20>o<EFBFBD><6F> */
}GAME;
void bubble_sort(GAME arr[], int total) {
int i,j;
for (i = 0; i < total - 1; i++) {
for (j = 0; j < total - i - 1; j++) {
if (arr[j].score < arr[j + 1].score) {
GAME temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main(){
GAME bowling[] = {{"Jack",198},{"Tom",185},{"Bob",210},{"Fred",205},{"Mary",170}};
int total =sizeof (bowling)/sizeof(bowling[0]);
bubble_sort(bowling,total);
int i,j;
printf("<EFBFBD><EFBFBD><EFBFBD>Z<EFBFBD>Ʀ<EFBFBD>\n");
printf("============\n");
for(j=0;j<total;j++){
printf("%d. %s\t%d\n",j+1,bowling[j].name,bowling[j].score);
}
return 0;
}