请各位大神帮忙添加一个数据结构排序的方法并在主函数中调用
程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct student *ST; struct student { int stnu; char stname[6]; char ststate[1]; ST next; }; ST head=NULL; int ShowNode() { int no; ST t; printf("输入学号:"); scanf("%d", &no); for (t = head; t; t = t->next) { if (t->stnu == no) { printf("|学号|:%d |姓名|:%s |是否缺席|:%s \n", t->stnu, t->stname,t->ststate); printf("是否缺席(缺席N,出席Y):"); scanf("%s", &t->ststate); return 0; } } printf("无此学生\n"); return 0; } void SelectNode() { ST t; int sum=0,i=0; for (t = head; t; t = t->next) { printf("学号:%d\n",t->stnu); printf("姓名:%s\n",t->stname); printf("出勤情况:%s\n",t->ststate); sum=++i; printf("☆---------------☆\n"); } printf("共有%d人",sum); } int InsertNode() { ST t; t = (ST)malloc(sizeof *t); printf("输入学号:"); scanf("%d", &t->stnu); printf("输入姓名:"); scanf("%s", &t->stname); printf("输入Y(默认出席):"); scanf("%s",&t->ststate); t->next = head; head = t; printf("添加成功"); return 0; } int DelNode() { ST x, y; int no; printf("输入学号:"); scanf("%d", &no); for (x = y = head; x; y = x, x = x->next) { if (x->stnu == no) { if (x == y) { x = head = head->next; y->next = NULL; free(y); printf("删除成功!\n"); return 0; } else { y->next = x->next; x->next = NULL; free(x); printf("删除成功!\n"); return 0; } } } printf("无此学生\n"); return 0; } int main(void) { int i; while(1) { printf("\n"); printf("☆---------------------------------☆\n"); printf("-----------☆ 点名开始 :1☆-----------\n" "-----------☆报道学生添加:2☆-----------\n" "-----------☆ 删除学生 :3☆-----------\n" "-----------☆ 查看全体 :4☆-----------\n" "-----------☆ 退 出 :5☆-----------\n"); printf("☆---------------------------------☆\n"); printf("请选择:"); scanf("%d", &i); if (i==1) { ShowNode(); //system("cls"); } else if(i==2) { InsertNode(); } else if(i==3) { DelNode(); } else if(i==4) { SelectNode(); } else if(i==5) { break; } else { printf("输入错误!请重新输入!\n"); continue; } } return 0; }