欢迎来到天天文库
浏览记录
ID:44509458
大小:742.79 KB
页数:53页
时间:2019-10-22
《数据结构链表例题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、数据结构》第三章线性链表的基本制作代码2007-04-1613:46'••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
2、••••••••!/*Note:YourchoiceisCIDE*/#include"stdio.h”structnode{intd;structnode*next;};voidinitll(structnode**head){intx;structnode*p/q;q=NULL;scanf("%d”,&x);while(x>0){p=(structnode*)malloc(sizeof(structnode));p->d=x;p->next=NULL;if(q==NULL)*head=p;elseq->next=p;q=p;scanf(n%dM3&x);}}voidmenu()printf
3、(M****u);printf(M**菜单printf(M****n);printf(M**1.链表初始化printf(M**2.链表插入printf(M**3.链表删除printf(M**4.链表输出printf(M**0.退出printf(M**请选择:M);prin廿(-);}voidlloutput(structnode*head)printf(n链表的内容:”);while(head!=NULL)printf(K%dM,head->d);head=head->next;structnode*lookst(head5x)intx;structnode*head;{st
4、ructnode*p;p=head;while((p->next!=NULL)&&(((p->next)->d)!=x))p=p->next;return(p);voidinslst(head)structnode**head;{intx,b;structnode*p3*q;printf(K请输入插入位置的数值:J;scanf「%cT;&x);printf(K请输入插入的数值:J;scanf(n%df&b);p=(structnode*)malloc(sizeof(structnode));p->d=b;if(*head==NULL){*head=p;p->next=NULL;return
5、;}if((*head)->d==x){p->next=*head;*head=p;return;}q=lookst(*head,x);p->next=q->next;q->next=p;return;}voiddelst(structnode**head){structnode*p5*q;intx;printf(M请输入要删除的数值:J;scanff%df&x);if(*head==NULL){printf(H链表是空表!”);return;}if(((*head)->d)==x){p=(*head)->next;free(*head);*head=p;return;}q=lookst(
6、*head,x);if(q->next==NULL){printf(M链表中没有相应的节点!n);return;}p=q->next;q->next=p->next;free(p);return;main()intch;structnode*head5*p,*q;menu();scanf(M%dM5&ch);while(ch!=0)switch(ch){case1:initll(&head);break;case2:inslst(&head);break;case3:delst(&head);break;case4:lloutput(head);break;menu();scanf(M%
7、dM,&ch);下一秒时间2008-12-2711:20#ineludettincludcttincludeWincludettinclude#ineludeintflag=l;classCdate//定义Cdate类{public:voidShowTimeO;//显示当前日期时间及第二天日期时
此文档下载收益归作者所有