資源描述:
《鏈表的綜合操作源程序》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、#include#include#include#defineLENsizeof(structstudent)structstudent{intnum;floatscore;structstudent*next;};voidmain()//主函數(shù){structstudent*creat(void);//建立一個動態(tài)鏈表structstudent*del(structstudent*head,intdel_num);//刪除鏈表structstudent*insert(structstudent
2、*head,structstudent*stu);//插入鏈表voidprint(structstudent*head);//輸出鏈表structstudent*head;structstudent*stu;//要插入的節(jié)點intdel_num;head=creat();//創(chuàng)建動態(tài)鏈表print(head);//輸出原鏈表printf("");//空一格printf("Inputthedeletedel_num:");scanf("%d",&del_num);while(del_num!=0)//多次刪除{head=del(head,del_n
3、um);printf("");printf("Thedeletedlistis:");print(head);printf("");printf("Inputthedeletedel_num:");scanf("%d",&del_num);}printf("");printf("Inputtheinsertnode:");stu=(structstudent*)malloc(LEN);scanf("%d,%f",&stu->num,&stu->score);while(stu->num!=0)//多次插入{head=insert(he
4、ad,stu);print(head);printf("");printf("Inputtheinsertnode:");stu=(structstudent*)malloc(LEN);scanf("%d,%f",&stu->num,&stu->score);}}/***************************************************//***************建立動態(tài)鏈表************************/structstudent*creat(void)//建立一個動態(tài)鏈表{intn;str
5、uctstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%d,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%d,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}/
6、***************************************************//***************刪除鏈表***************************/structstudent*del(structstudent*head,intdel_num){structstudent*p1,*p2;if(head==NULL)printf("Thisisanulllist!");p1=head;while(del_num!=p1->num&&p1->num!=NULL){p2=p1;p1=p1->next;
7、}if(del_num==p1->num){if(p1==head)head=p1->next;elsep2->next=p1->next;printf("delete:%d",del_num);}elseprintf("%dnotbeenfound!",del_num);return(head);}/***************************************************//***************插入鏈表節(jié)點************************/structstudent*insert(st
8、ructstudent*head,structstudent*stu){structstudent*p0,*