#include
#include
struct student
{
int num;
char name[20];
int grade1;
int grade2;
int grade3;
int grade4;
int grade5;
float avgeage;
struct student *next;
};
struct student *finds(struct student *p)
{
int num;
printf("输入学号:\n");
scanf("%d",&num);
while(p->next!=NULL)
{
p=p->next;
if(p->num==num)
{
return p;
}
}
return NULL;
}
struct student print(struct student *p)
{
struct student *change;
change=p;
change=change->next;
printf("学号 姓名 姓名\n");
while(change!=NULL)
{
printf("%-8d%-8s%-8d\n",change->num,change->name,change->grade1);
change=change->next;
}
}
struct student *funs(void)
{
struct student *head,*p1,*p2;
head=p2=(struct student *)malloc(sizeof(struct student));//head,p2指向头结点
printf("输入学号 姓名 成绩:(学号输入0结束)\n");
p1=(struct student *)malloc(sizeof(struct student));//p1指向第一个结点
scanf("%d%s%d",&p1->num,p1->name,&p1->grade1);
while(p1->num!=0)
{
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
scanf("%d%s%d",&p1->num,p1->name,&p1->grade1);
}
p2->next=NULL;
free(p1);
return head;
}
delete_m(struct student *p)
{
struct student *p1;
long number;
printf("输入要删除的学号\n");
scanf("%ld",&number);
p1=p->next;
while(p1!=NULL)
{
if(p1->num==number)
{
p->next=p1->next;
free(p1);
printf("已删除\n");
return 1;
}
else
{
p=p1;
p1=p1->next;
}
}
printf("NO FOUND\n");
}
insert(struct student *p)
{
struct student *p1;
printf("输入插入学号 姓名 成绩\n");
p1=(struct student *)malloc(sizeof(struct student));
scanf("%d%s%d",&p1->num,p1->name,&p1->grade1);
while(p->next!=NULL && p->next->num < p1->num)
{
p=p->next;
}
if(p->next!=NULL && p->next->num == p1->num)
{
free(p1);
printf("插入的信息已存在:\n");
return 0;
}
else
{
p1->next=p->next;
p->next=p1;
return 1;
}
}
main()
{
struct student *head,*finds1;
int m=10,x,y;
head=funs();
printf("************************************\n");
printf("*欢迎来到学生信息系统 *\n");
printf("*输入1查看所有学生信息 *\n");
printf("*输入2查看单个学生信息 *\n");
printf("*输入3删除学生信息 *\n");
printf("*输入4插入学生信息 *\n");
printf("*输入0退出系统 *\n");
printf("************************************\n");
while(m!=0)
{
printf("输入你要进行的操作\n");
scanf("%d",&m);
switch(m)
{
case 1:print(head);break;
case 2:finds1=finds(head);
if(finds1!=NULL)
{
printf("学号 姓名 成绩\n");
printf("%-8d%-8s%-8d\n",finds1->num,finds1->name,finds1->grade1);
}
else
printf("NO FOUND\n");
break;
case 3:delete_m(head);
print(head);break;
case 4:insert(head);
print(head);break;
}
}
printf("再见\n");
}
多余的自己删了