mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
74 lines
1.1 KiB
Markdown
74 lines
1.1 KiB
Markdown
|
# 6-4 利用“选择排序算法“对结构体数组进行排序
|
|||
|
|
|||
|
本题:补充函数 sortByChoose()的剩余部分,其要求是利用选择排序算法根据学生成绩(score)实现对结构体数组元素降序排序。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
void sortByChoose(struct Student *pData,int n);
|
|||
|
```
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include<stdio.h>
|
|||
|
#include<stdlib.h>
|
|||
|
#define N 10
|
|||
|
struct Student
|
|||
|
{
|
|||
|
int num;
|
|||
|
int score;
|
|||
|
};
|
|||
|
|
|||
|
void sortByChoose(struct Student *pData,int n);
|
|||
|
|
|||
|
int main(void)
|
|||
|
{
|
|||
|
struct Student data[10],*p;
|
|||
|
int i;
|
|||
|
|
|||
|
for(p=data,i=0;i<N;i++)
|
|||
|
{
|
|||
|
scanf("%d %d",&p->num,&p->score);
|
|||
|
p++;
|
|||
|
}
|
|||
|
sortByChoose(data,N);
|
|||
|
for (p=data,i=0;i<N;i++)
|
|||
|
{
|
|||
|
printf("%2d-%-5d", p->num, p->score);
|
|||
|
p++;
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
void sortByChoose(struct Student *pData,int n)
|
|||
|
{
|
|||
|
struct Student *p1,*p2,*p;
|
|||
|
int num, score,i,j;
|
|||
|
for(p1=pData;p1<pData+n-1;p1++)
|
|||
|
{
|
|||
|
/* 请在这里填写答案 */
|
|||
|
}
|
|||
|
}
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例:
|
|||
|
|
|||
|
```in
|
|||
|
29 90
|
|||
|
15 80
|
|||
|
87 55
|
|||
|
65 84
|
|||
|
35 80
|
|||
|
33 55
|
|||
|
44 79
|
|||
|
99 80
|
|||
|
89 80
|
|||
|
41 55
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例:
|
|||
|
|
|||
|
```out
|
|||
|
29-90 65-84 15-80 35-80 99-80 89-80 44-79 87-55 33-55 41-55
|
|||
|
```
|