预览加载中,请您耐心等待几秒...
在线预览结束,喜欢就下载吧,查找使用更方便
如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
C语言之链表的基本操作#include"stdio.h"#include"malloc.h"typedefstructstudent{intnum;floatscore;structstudent*next;}stu,*p_stu;voidprint(p_stuhead);p_stuinsert(p_stuhead,p_stustu);p_stuDelete(p_stuhead,longscore);intmain(){stua,b,c,d;p_stuhead;a.num=1;a.score=96;b.num=2;b.score=98;c.num=3;c.score=100;d.num=4;d.score=97;head=&a;a.next=&b;b.next=&c;c.next=NULL;print(head);insert(head,&d);printf("insertfinished\n");print(head);Delete(head,b.score);printf("Deletefinished\n");print(head);}voidprint(p_stuhead){structstudent*p;p=head;while(p!=NULL){printf("num=%dscore=%3.2f\n",p->num,p->score);p=p->next;}}p_stuinsert(p_stuhead,p_stustu){p_stup1,p2,p0;p1=head;p0=stu;if(head==NULL){head=p0;p0->next=NULL;}while((p0->score>p1->score)&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p0->score<=p1->score){if(p1==head){head=p0;p0->next=p1;}else{p2->next=p0;p0->next=p1;}}else{p1->next=p0;p0->next=NULL;}returnhead;}p_stuDelete(p_stuhead,longscore){p_stup1,p2;p1=head;if(head==NULL){printf("Listisnull\n");gotoend;}while((score!=p1->score)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(score==p1->score){if(p1==head){head=p1->next;}else{p2->next=p1->next;printf("Deletescore=%d\n",score);}}end:returnhead;}