数据结构链表例题

数据结构链表例题

ID:44509458

大小:742.79 KB

页数:53页

时间:2019-10-22

数据结构链表例题_第1页
数据结构链表例题_第2页
数据结构链表例题_第3页
数据结构链表例题_第4页
数据结构链表例题_第5页
资源描述:

《数据结构链表例题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

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;//显示当前日期时间及第二天日期时

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。