37 lines
788 B
C
37 lines
788 B
C
#include <stdio.h>
|
|
|
|
typedef struct game {
|
|
char name[8]; /* 參賽者姓名 */
|
|
int score; /* 得分 */
|
|
}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("成績排行\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;
|
|
}
|
|
|