C语言 双向链表的建立 删除 插入.docx

上传人:小飞机 文档编号:3155168 上传时间:2023-03-11 格式:DOCX 页数:4 大小:36.52KB
返回 下载 相关 举报
C语言 双向链表的建立 删除 插入.docx_第1页
第1页 / 共4页
C语言 双向链表的建立 删除 插入.docx_第2页
第2页 / 共4页
C语言 双向链表的建立 删除 插入.docx_第3页
第3页 / 共4页
C语言 双向链表的建立 删除 插入.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《C语言 双向链表的建立 删除 插入.docx》由会员分享,可在线阅读,更多相关《C语言 双向链表的建立 删除 插入.docx(4页珍藏版)》请在三一办公上搜索。

1、C语言 双向链表的建立 删除 插入双向链表建立struct dnodeint data;struct dnode *prv;struct dnode *next;struct dnode *creatlist(int a)struct dnode *head=NULL,*p=NULL;head=(struct dnode *)malloc(sizeof(struct dnode);if(!head)perror(head malloc);head->prv=head->next=NULL; while(a)p=(struct dnode *)malloc(sizeof(struct d

2、node);if(!p)perror(p malloc);p->data=a-;p->next=head->next;head->next=p;p->prv=head;if(p->next!=NULL)p->next->prv=p;p=NULL;双向链表删除int dellist(struct list *head,int key)struct list *p,*w;if(head->next=NULL)return 1;/链表为空p=head;while(p->next!=NULL)/查找key值所在节点。if(p->next->data=ke

3、y)break;/命中p=p->next;if(p->prv)p->prv->next=p->next;if(p->next)p->next->prv=p->prv;free(p);双向链表插入int insert(struct dnode *head,int key,int a)struct dnode *p,*w=NULL;w=(struct dnode *)malloc(sizeof(struct dnode);if(!w)perrpr(w malloc);w->data=a;p=head->next;while(p&(p->data!=key)p=p->next;if(!p)return 1;p->prv->next=w;w->prv=p->prv;w->next=p;p->prv=w;return 1;版权:作孽

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号