线性表应用举例PPT课件

上传人:cn****1 文档编号:577488043 上传时间:2024-08-22 格式:PPT 页数:13 大小:138.50KB
返回 下载 相关 举报
线性表应用举例PPT课件_第1页
第1页 / 共13页
线性表应用举例PPT课件_第2页
第2页 / 共13页
线性表应用举例PPT课件_第3页
第3页 / 共13页
线性表应用举例PPT课件_第4页
第4页 / 共13页
线性表应用举例PPT课件_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《线性表应用举例PPT课件》由会员分享,可在线阅读,更多相关《线性表应用举例PPT课件(13页珍藏版)》请在金锄头文库上搜索。

1、第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构线性表应用举例按正位序创建一个带表头结点的单链表1 1、预定义常量与存储结构描述、预定义常量与存储结构描述 #define NULL 0 /预定义常量 typedef struct LNode char data; struct LNode *next; LNode,*Linklist; /存储结构描述1第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构2 2、定义在存储结构上的操作、定义在存储结构上的操作void create_L_zx(Linklist L) int i,n; Linklist q,p; prin

2、tf(input n:); scanf(%d%*c,&n); q=L; for(i=0;idata); p-next=NULL; q-next=p;q=p; 2第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构void print_L(Linklist L) Linklist p; printf(The list is:n); p=L-next; while(p) printf(%3c,p-data); p=p-next; printf(n);3第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构3 3、测试程序、测试程序main() Linklist L; clrs

3、cr(); L=(Linklist)malloc(sizeof(LNode); L-next=NULL; create_L_zx(L); print_L(L);4第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构按正位序创建一个不带表头结点的单链表1 1、创建、创建p=(Linklist)malloc(sizeof(LNode); /第一个结点第一个结点scanf(%c,&p-data);L=p;q=p;for(i=2;idata); p-next=NULL; q-next=p;q=p; 2 2、打印、打印 p=L;3 3、测试、测试 L=NULL;5第第2 2章章 线性线性表表

4、 D.S. D.S.数据结构数据结构在单链表中删除所有值为在单链表中删除所有值为x x的结点的结点main() int x,i,n; Linklist L,p,q; clrscr(); L=(Linklist)malloc(sizeof(LNode); /建立空链表建立空链表 L-next=NULL; printf(input n:); scanf(%d,&n); for(i=n;i0;i-) /按逆位序创建单链表按逆位序创建单链表 p=(Linklist)malloc(sizeof(LNode); scanf(%d,&p-data); p-next=L-next; L-next=p; 6第第

5、2 2章章 线性线性表表 D.S. D.S.数据结构数据结构p=L-next; /打印单链表打印单链表 while(p) printf(%4d,p-data); p=p-next; printf(ninput x:); scanf(%d,&x); p=L; while(p-next) if(p-next-data=x) q=p-next; p-next=q-next; free(q); else p=p-next;p=L-next; while(p) printf(%4d,p-data); p=p-next; 7第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构建立一个线性链表建

6、立一个线性链表head=3head=3,5 5,7 7,99,其元素值依次为从键盘输入正整数,其元素值依次为从键盘输入正整数(以输入一个非正整数为结束);在(以输入一个非正整数为结束);在线性表中值为线性表中值为x x的元素前插入一个值为的元素前插入一个值为y y的数据元素。若值为的数据元素。若值为x x的结点不存在,的结点不存在,则将则将y y插在表尾。插在表尾。8第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构 1 1、建立头文件:、建立头文件:linkh.hlinkh.h #define NULL 0 /*预定义常量*/ typedef int ElemType; typ

7、edef struct LNode ElemTpye data; struct LNode *next; LNode,*Linklist; /*存储结构描述*/9第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构/*/*定义在存储结构上的操作定义在存储结构上的操作*/*/void create_L(Linklist L) Linklist p,q; ElemType d; q=L; printf(input datas in the list(end of 0):); scanf(%d,&d); while(d0) p=(Linklist)malloc(sizeof(LNode)

8、; p-data=d; p-next=NULL; q-next=p; q=p; scanf(%d,&d); 10第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构void print_L(Linklist L) Linklist p; printf(The list is:n); p=L-next; while(p) printf(%4d,p-data); p=p-next; printf(n);11第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构void Insert_x_y(Linklist L) ElemType x,y; Linklist s,q,p; p

9、rintf(ninput x,y:); scanf(%d,%d,&x,&y); s=(Linklist)malloc(sizeof(LNode); s-data=y; q=L; p=q-next; while(p!=NULL)&(p-data!=x) q=p; p=p-next; s-next=p; q-next=s;12第第2 2章章 线性线性表表 D.S. D.S.数据结构数据结构2 2、建立源程序文件测试:、建立源程序文件测试:ceshi.cceshi.c #include linkh.h /*文件包含*/ main() Linklist L; clrscr(); L=(Linklist)malloc(sizeof(LNode); L-next=NULL; create_L(L); print_L(L); Insert_x_y(L); print_L(L); 13

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 医学/心理学 > 基础医学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号