欢迎来到天天文库
浏览记录
ID:9409011
大小:27.50 KB
页数:6页
时间:2018-04-30
《c语言建立输出插入删除修改功能的单项动态链表》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、C语言链表类题目写函数一个有三名学生数据的,有建立输出插入删除修改功能的单项动态链表,很全面,各种测试都试过了,环境VC6.0结构体为学号成绩#include#include#includestructStudent{longnum;floatscore;structStudent*next;structStudent*pre;};intn=0;structStudent*create(void){structStudent*head;structStudent*tail;struct
2、Student*pre;structStudent*p;head=NULL;pre=NULL;p=(structStudent*)malloc(sizeof(structStudent));printf("请输入用户名和得分:");scanf("%ld%f",&p->num,&p->score);if(0==p->num){returnNULL;}while(0!=p->num){n++;if(NULL==head){head=p;tail=p;pre=NULL;tail->next=NULL;}else{pre=tail;tail->n
3、ext=p;tail=p;}p=(structStudent*)malloc(sizeof(structStudent));printf("请输入用户名和得分:");scanf("%ld%f",&p->num,&p->score);}if(NULL!=pre){tail->next=NULL;}returnhead;}voidprint(structStudent*head){structStudent*p=head;if(NULL==p){printf("该链表中还没有数据");}while(p!=NULL){printf("%ld
4、t%.3f",p->num,p->score);p=p->next;}}structStudent*del(structStudent*head,longnum){structStudent*p1=head;structStudent*p2=head;if(NULL==head){returnNULL;}if(NULL==head->next){if(num==head->num){n--;returnNULL;}else{returnhead;}}if(num==head->num){n--;head=head->next;retur
5、nhead;}if(NULL==head->next->next){if(num==head->next->num){n--;head->next=NULL;returnhead;}}p1=head->next;while(p1!=NULL){if(num==p1->num){n--;if(NULL==p1->next){p2->next=NULL;}else{p2->next=p1->next;}}p1=p1->next;p2=p2->next;}returnhead;}structStudent*alter(structStudent*h
6、ead,longnum,floatscore){structStudent*p=head;while(p!=NULL){if(num==p->num){p->score=score;}p=p->next;}returnhead;}structStudent*insert(structStudent*head,longnum,floatscore){structStudent*p1=head;structStudent*p2=head;structStudent*p;p=(structStudent*)malloc(sizeof(structS
7、tudent));p->num=num;p->score=score;if(NULL==head){head=p;head->next=NULL;returnhead;}if(NULL==head->next){if(num>=head->num){head->next=p;p->next=NULL;returnhead;}else{p->next=head;head=p;returnhead;}}if(numnum){p->next=head;head=p;returnhead;}p1=head->next;while(p1!
8、=NULL){if(num>=p2->num){if(num<=p1->num){p->next=p1;p2->next=p;}else{if(NULL==p1->
此文档下载收益归作者所有