已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
include stdio h include stdlib h typedef struct List int data struct List next 指针域 List void HeadCreatList List L 头插法建立链表 List s L next NULL for int i 0 idata i s next L next 将 L 指向的地址赋值给 S L next s void TailCreatList List L 尾插法建立链表 List s r r L for int i 0 idata i r next s r s r next NULL void DisPlay List L List p L next while p NULL printf d p data p p next printf n int main List L1 L2 L1 struct List malloc sizeof struct List L2 struct List malloc sizeof struct List HeadCreatList L1 DisPlay L1 TailCreatList L2 DisPlay L2 头插法创建链表头插法创建链表 include include struct node int data struct node next 建立只含头结点的空链表 struct node create list struct node head NULL head struct node malloc sizeof struct node if NULL head printf memory out of use n return NULL head next NULL head data 0 return head 头插法建立链表 int insert form head struct node head int num struct node head t head next struct node new node NULL new node struct node malloc sizeof struct node if NULL new node printf memory out of use n return 1 将新结点插入到链表的最后 new node data num new node next head t head next new node return 0 打印链表 int show list struct node head struct node temp temp head next while temp printf d n temp data temp temp next return 0 按值删除结点 头结点不被删除 int delete node struct node head int data head t 保存要删除结点的上一个结点 struct node head t head struct node temp NULL if head NULL printf delete node from empty list n return 1 查找删除的结点的前一个结点 如果此处查找的是删除的结点 则需要另加一个指针保存删除结点的前一个指针 while NULL head t next if data head t next data break head t head t next 如果要删除的结点不存在 直接返回 if NULL head t next printf node not found n return 1 删除操作 temp head t next head t next head t next next free temp return 0 void main int argc char argv struct node head head create list if NULL head printf create list error n insert form head head 123 insert form head head 456 show list head printf delete once n delete node head 123 show list head printf delete second n delete node head 456 show list head delete node head 0 show list head 尾插法创建链表尾插法创建链表 include include struct Node int data struct Node next 建立只含头结点的空链表 struct Node create list struct Node head NULL head struct Node malloc sizeof struct Node if NULL head printf memory out of use n return NULL head next NULL head data 0 return head 尾插法建立链表 int insert form tail struct Node head int num struct Node temp head struct Node new node NULL new node struct Node malloc sizeof struct Node if NULL new node printf memory out of use n return 1 寻找尾结点 while temp next NULL temp temp next 将新结点插入到链表的最后 new node data num new node next NULL temp next new node return 0 打印链表 int show list struct Node head struct Node temp temp head next while temp printf d n temp data temp temp next return 0 void main int argc char arg
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 沪教数学一年级上第五单元加倍与一半测试卷(附答案)
- 中药师规范化培训试题及答案
- 安全生产建筑施工高温危害防范培训试题及答案
- 工厂职业健康培训人工智能辅助职业健康管理试题及答案剖析
- 邮政停投协议书
- 农庄农场出售合同范本
- 输血操作规程培训考试试题及答案
- 社群基础运营 课件2
- 2025年山东省物流工程专业职称(中级)核心考点速记速练300题(附答案)
- 2025年《汽车底盘构造与维修》核心备考题库(含典型题、重点题)
- 人教版 数学 三年级上册 解决问题专项训练
- MOOC 跨文化交际通识通论-扬州大学 中国大学慕课答案
- 小青瓦屋面施工方案
- 《水文化导论》课件
- 六年级下册道德与法治地球我们的家园
- 大桥结构健康监测系统项目监理规划
- 腹腔镜胃癌根治术护理教学查房
- DB23T 2334-2019 装配式混凝土渠道应用技术规范
- 酒店公寓物业管理规约
- 通透(杨天真重磅新作)
- DB32-T 4281-2022 江苏省建筑工程施工现场专业人员配备标准
评论
0/150
提交评论