2022年数据结构C语言版单链表源代码 3.pdf

上传人:Q****o 文档编号:25952123 上传时间:2022-07-14 格式:PDF 页数:10 大小:48.73KB
返回 下载 相关 举报
2022年数据结构C语言版单链表源代码 3.pdf_第1页
第1页 / 共10页
2022年数据结构C语言版单链表源代码 3.pdf_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《2022年数据结构C语言版单链表源代码 3.pdf》由会员分享,可在线阅读,更多相关《2022年数据结构C语言版单链表源代码 3.pdf(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、/* 单链表的各种操作 */ #include #include #define null 0 typedef int ElemType; /* 字符型数据 */ struct LNode ElemType data; struct LNode *next; ; void setnull(struct LNode *p); int length (struct LNode *p); ElemType get(struct LNode *p,int i); void insert(struct LNode *p,ElemType x,int i); void dele(struct LNode

2、*p,int i); void display(struct LNode *p); int locate(struct LNode *p,ElemType x); void main() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - struct LNode *head,*q; /*定义静态变量 */ int select,x1,x2,x3,x4; int i,n; int m,g; char e,y; setnull(&h

3、ead); /* 建设链表并设置为空表*/ printf( 请输入数据长度 : ); scanf(%d,&n); for(i=1;inext; return(n); ElemType get(struct LNode *p,int i) int j=1; struct LNode *q=*p; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 10 页 - - - - - - - - - while (jnext; j+; if(q!=null) return(q-data

4、); else printf( 位置参数不正确 !n); return 0; int locate(struct LNode *p,ElemType x) int n=0; struct LNode *q=*p; while (q!=null&q-data!=x) q=q-next; n+; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 10 页 - - - - - - - - - if(q=null) return(-1); else return(n+1); voi

5、d insert(struct LNode *p,ElemType x,int i) int j=1; struct LNode *s,*q; s=(struct LNode *)malloc(sizeof(struct LNode); s-data=x; q=*p; if(i=1) s-next=q; *p=s; else while(jnext!=null) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 10 页 - - - - - - - - - q=q-next

6、; j+; if(j=i-1) s-next=q-next; q-next=s; else printf( 位置参数不正确 !n); void dele(struct LNode *p,int i) int j=1; struct LNode *q=*p,*t; if(i=1) t=q; *p=q-next; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 10 页 - - - - - - - - - else while(jnext!=null) q=q-next; j

7、+; if(q-next!=null&j=i-1) t=q-next; q-next=t-next; else printf( 位置参数不正确 !n); if(t!=null) free(t); void display(struct LNode *p) struct LNode *q; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 10 页 - - - - - - - - - q=*p; printf( 单链表显示 : ); if(q=null) printf( 链表为空 !); else if (q-next=null) printf(%dn,q-data); else while(q-next!=null) printf(%d-,q-data); q=q-next; printf(%d,q-data); printf(n); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 10 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 技术总结

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com