本题要求实现多个函数完成对链表的各项基本操作:创建链表,按要求查找,在指定位置添加结点,删除结点,链表排序,输出链表等操作。
链表中为若干个学生的信息(学号、成绩),当输入学号为0时结束;查找并输出不及格的学生信息;新增一个学生信息到指定的学号前面;将指定学号的学生从链表中删除。 将链表中的学生信息按照分数降序排序。
函数接口定义:
Stu * Creatlink( );
void Printlink(Stu * head);
void Search(Stu * head);
Stu *Delnode(Stu * head,int n);
Stu * Addnode(Stu * head,int n);
Stu *Sortnode(Stu * head);
裁判测试程序样例:
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct stu)
struct stu
{
int num;
float score;
struct stu *next;
};
typedef struct stu Stu;
Stu *Creatlink();
void Printlink(Stu *head);
void Search(Stu *head);
Stu *Delnode(Stu *head,int n);
Stu *Addnode(Stu *head,int n);
Stu *Sortnode(Stu *head);
int main()
{
Stu *head = NULL;
int num;
head = Creatlink();
if(head !=NULL)
Printlink(head);
else
{
printf("Empty list\n");
return 0;
}
printf("The student no pass:\n");
Search(head);
scanf("%d",&num);
head=Delnode(head,num);
if(head !=NULL)
{
printf("After delete the student:\n");
Printlink(head);
}
else
{
printf("After delete:empty list\n");
return 0;
}
scanf("%d",&num);
head=Addnode(head,num);
printf("After add the student:\n");
Printlink(head);
head = Sortnode(head);
printf("After sorted:\n");
Printlink(head);
return 0;
}
/* 请在这里填写答案 */
输入样例:
2,58
3,69
4,98
5,45
6,30
9,80
11,40
0,0
6
9
7,88
输出样例:
2,58
3,69
4,98
5,45
6,30
9,80
11,40
The student no pass:
2,58
5,45
6,30
11,40
After delete the student:
2,58
3,69
4,98
5,45
9,80
11,40
After add the student:
2,58
3,69
4,98
5,45
7,88
9,80
11,40
After sorted:
4,98
7,88
9,80
3,69
2,58
5,45
11,40
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB