资源描述:
《链表实现学生系统》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、姓名:许江华双向循坏链作业学号:S130101200#include#include#defineNULLO#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next,*prior;};intn;structstudent*creat(void){structstudent*head;structstudent*pl,*p2;n=0;pl=p2=(structstudent*)malloc(
2、LEN);scanf("%ld,%f&p1->num,&p1->score);head二NULL;while(p1->num!=0){n=n+l;if(n==1){head=p1;head->next=head;head->prior=head;}else{p2->next=p1;pl->prior=p2;p1->next=head;head->prior=p1;}p2=pl;p
3、=(structstudent*)mal!oc(LEN);scanf("%]d,%f',&pl->num,&p1->score);}return(head
4、);voidprint(structstudent*head){structstudent*p;printf(HNow,these%drecordare:n,n);p=head;if((head!=NULL)&&(n>0))do{printf(nnum%ld,score%5・1frf;p・>num,p・>scoi・e);p=p->next;}while((p!=head));}structstudent*dcl(structstudent*head,longnum){structstudent*pl,*p2;if(head
5、==NULL){printf("空表");retumhead;)pl=head;while((num!=p1->num)&&(p1->next!=head)){p2=pl;pl=pl->next;}if(num==p1->num)(if(pl==head){p1->next->prior=p1->prior;p1->prior->next=p1->next;head=p1->next;)else{p1->prior->next=p1・>next;p1->next->prior=p1->prior;}//printf("delete:
6、%ld°,num);n=n-l;}elseprintf(Hld%notbeenfondH,num);return(head);structstudent*insert(structstudent*head,structstudent*stu){structstudent*p0,*pl,*p2;pO=stu;if(head==NULL){head=pO;}//pO->next=head;else{pl二head;while((pO->num>p1->num)&&(p1->next!=head)){p2二pl;pl=pl->next
7、;}if(pO->num<=p1->num){if(head==p1){pO->next=pI;p1->prior->next=pO;p1->prior=pO;pO->prior=p1->prior;head=pO;)else{p2->next=p0;p0->next=p1;p0->prior=p2;p1->prior=pO;}}else{p1->next=pO;pO->prior=p1;pO->next=head;head->prior=pO;}}n=n+l;return(head);}structstudent*query(st
8、mc(student*head,structstudent*stud){structstudent*p1;pl=head;if(head==NULL){printf("空表");rctumhead;}whilc((pl->num!=stud->num)&&(pl->ncxt!=hcad))pl=pl->next;if(p1->num==stud->num)printf(Hnum%ld,score%5.1fstudenthasexistn,pl->num,p1->score);elseprintf(uthestudentnotex
9、istH);}structstudent*modify(structstudent*head,structstudent*mod){structstudent*p3;p3=head;printf("thisis%5.lfM,m