|
|
|
@ -185,7 +185,26 @@ void AverSumofEveryCourse(STU stu[],int n,int m)
|
|
|
|
|
```
|
|
|
|
|
voidSortbyScore(STU stu[],int n,int m,int(*compare)(float a,float b))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int i, j, k, t;
|
|
|
|
|
for (i=0; i<n-1; i++)
|
|
|
|
|
{
|
|
|
|
|
k = i;
|
|
|
|
|
for (j=i+1; j<n; j++)
|
|
|
|
|
{
|
|
|
|
|
if ((*compare)(stu[j].sum, stu[k].sum)) k = j;
|
|
|
|
|
}
|
|
|
|
|
if (k != i)
|
|
|
|
|
{
|
|
|
|
|
for (t=0; t<m; t++) //交换m门课程的成绩
|
|
|
|
|
{
|
|
|
|
|
SwapFloat(&stu[k].score[t], &stu[i].score[t]);
|
|
|
|
|
}
|
|
|
|
|
SwapFloat(&stu[k].sum, &stu[i].sum); //交换总分
|
|
|
|
|
SwapFloat(&stu[k].aver, &stu[i].aver); //交换平均分
|
|
|
|
|
SwapLong(&stu[k].num, &stu[i].num); //交换学号
|
|
|
|
|
SwapChar(stu[k].name, stu[i].name); //交换姓名
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
@ -238,17 +257,18 @@ void SwapChar(char x[],chary[])
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//函数功能:按选择法将数组 sum 的元素从低到高排序
|
|
|
|
|
//函数功能:按选择法将数组 num 的元素从低到高排序
|
|
|
|
|
```
|
|
|
|
|
void AsSortbyNum(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j, k, t;
|
|
|
|
|
int i, j, k, t;
|
|
|
|
|
for (i=0; i<n-1; i++)
|
|
|
|
|
{
|
|
|
|
|
int i, j, k, t;
|
|
|
|
|
k = i;
|
|
|
|
|
for (j=i+1; j<n; j++)
|
|
|
|
|
{
|
|
|
|
|
if ((*compare)(stu[j].sum, stu[k].sum)) k = j;
|
|
|
|
|
if (stu[j].num < stu[k].num) k = j;
|
|
|
|
|
}
|
|
|
|
|
if (k != i)
|
|
|
|
|
{
|
|
|
|
|