/*查找链表*/
struct stu *find1(struct stu *p) { int number; if(p==NULL) {
printf(\提示:没有资料可以查询!\\n\ return 0; } printf(\请输入要查找的学生学号:\ scanf(\ while(p!=NULL) { if(p->number==number) { return(p); break; } else p=p->next; }
return NULL; }
struct stu *find2(struct stu *p) { char name[30]; if(p==NULL) {
printf(\提示:没有资料可以查询!\\n\ return 0; } printf(\请输入要查找的学生姓名:\ scanf(\ while(p!=NULL) { if(strcmp(p->name,name)==0) return(p); else p=p->next; }
return NULL; }
/*删除链表*/
int del(struct stu **h) { int number;
struct stu *p,*p0; if(*h==NULL) return 0; printf(\请输入要删除的学号\\n\ scanf(\ p0=*h; if(p0->number==number) { *h=p0->next; free(p0); return 1; } p=p0->next; while(p!=NULL) { if(p->number==number) { p0->next=p->next; free(p); return 1; } p0=p; p=p->next; } printf(\按回车键返回\\n\ getchar(); return 0; }
/*插入链表*/
int insert (struct stu **h) { struct stu *p,*p0; p=(struct stu *)malloc(N); printf(\请输入要插入的学号\\n\ scanf(\ p0=*h;
if(p0->number==p->number) return 0; printf(\姓名\\n\ scanf(\ printf(\性别\\n\ scanf(\ printf(\出生日期\\n\ scanf(\ printf(\ scanf(\ printf(\电话\\n\
scanf(\ printf(\成绩\\n\ scanf(\ printf(\数学成绩\\n\ scanf(\ p->next=NULL; if(*h==NULL) { *h=p; return 1; } p0=*h; if(p0->number>p->number) { p->next=*h; *h=p; return 1; } while(p0->next!=NULL&&p0->next->number
/*排序*/
struct stu* sort(struct stu *p0) { struct stu *t,*p,*q,*z; if(p0==NULL) { printf(\没有学生信息可排序!\\n\ return 0; } if((p0==NULL)||(p0->next==NULL))/*当节点不存在或者只有一个节点时*/ { return p0; } t=p0; p=t->next; t->next=NULL; /*将头节点孤立出来*/ while(p) /*t始终指向头节点*/ { q=p->next; if(p->cscore>t->cscore) /*用头节点的后一个节点与头节点进行比较*/ { p->next=t; /*将分数大的放在前面*/ t=p; /*t始终指向当前第一个节点*/ } else { z=t; while(z->next&&z->next->cscore>=p->cscore) z=z->next; p->next=z->next; z->next=p; } p=q; } p0=t; return p0; }
void main() {
相关推荐: