双向链表插入删除基本应用介绍

2016-02-19 11:51 1 1 收藏

下面,图老师小编带您去了解一下双向链表插入删除基本应用介绍,生活就是不断的发现新事物,get新技能~

【 tulaoshi.com - 编程语言 】

双链表其实 也没什么 只是多了一个前置链而已
双链表的定义
代码如下:

struct DNode
{
int data;
struct DNode *next;
struct DNode *pre;
};

单链表的定义
代码如下:

view plaincopy
struct DNode
{
int data;
struct DNode *next;
};

其他的可以看上一篇博客 大致相同
代码如下:

#ifndef HEAD_H
#define HEAD_H
#include iostream
using namespace std;
#include cassert
#include cstdlib
#include cmath
#include sstream
#include fstream
#include string
#include algorithm
#include list
#include queue
#include vector
#include deque
#include stack
#include bitset
#include set
#include map
#endif
struct DNode
{
int data;
struct DNode *next;
struct DNode *pre;
};
DNode *Creat()

DNode *head,*p,*s;
head=(DNode *)malloc(sizeof(DNode));
p=head;
int temp;
while (cintemp&&temp)
{
s=(DNode *)malloc(sizeof(DNode));
s-data=temp;
p-next=s;
s-pre=p;
p=s;
}
head=head-next;
p-next=NULL;
head-pre=NULL;
return (head);
}
DNode *Insert(DNode *&head,int num)
{
DNode *p,*s;
s=(DNode *)malloc(sizeof(DNode));
s-data=num;
p=head;
while (NULL!=p-next&&nump-data)
{
p=p-next;
}
if (num=p-data)
{
if (NULL==p-pre)
{
s-next=head;
head-pre=s;
head=s;
head-pre=NULL;
}
else
{
s-pre=p-pre;
p-pre-next=s;
s-next=p;
p-pre=s;
}
}
else
{
p-next=s;
s-pre=p;
s-next=NULL;
}
return(head);
}
DNode *Del(DNode *&head,int num)
{
DNode *p;
p=head;
while (NULL!=p-next&&num!=p-data)
{
p=p-next;
}
if (num==p-data)
{
if (NULL==p-pre)
{
head=p-next;
p-next-pre=head;
free(p);
}
else if (NULL==p-next)
{
p-pre-next=NULL;
free(p);
}
else
{
p-pre-next=p-next;
p-next-pre=p-pre;
free(p);
}
}
else
{
coutnum" cound not be found"endl;
}
return head;
}
void Display(DNode *head)
{
DNode *p;
p=head;
while (NULL!=p)
{
cout(p-data)" ";
p=p-next;
}
coutendl;
}

代码如下:

#include "head.h"
int main()
{
DNode *head;
head=Creat();
Display(head);
#ifndef DEBUG
cout"please input an num to insert:";
#endif
int insert_num;
while (cininsert_num&&insert_num)
{
Insert(head,insert_num);
Display(head);
}
#ifndef DEBUG
cout"please input an number to delete:";
#endif
int delete_num;
while (cindelete_num&&delete_num)
{
Del(head,delete_num);
Display(head);
}
return (EXIT_SUCCESS);
}

来源:https://www.tulaoshi.com/n/20160219/1598907.html

延伸阅读
360安全桌面怎么删除应用   1.左键长击任意一个应用,所有应用上会出现红色x,点击即删除应用。任意点击空白处x即消失。 2.右键点击管理,也可以出现红色x。 3.右键点击应用,选择删除。   
iphoTulaoshi.comne如何防止应用被删除? 有人说iPhone之所以这么流行,最大的原因就是它有成千上万的应用可以安装,这也是其他任何手机也无法达到的。当你把手机借给其他好友使用时,如果他不小心删除了你iPhone上的某些程序,导致数据丢失,这样的情况是非常容易出现的。还有就是可能有人在借用iPhone时恶意帮你安装应用,盗取你iPhone...
标签: 电脑入门
您可将批注 (批注:作者或审阅者为文档添加的注释或批注。Microsoft Word 在文档的页边距或审阅窗格中的气球上显示批注。)插入到文档的页边距处出现的批注框 (批注框:在页面视图或 Web 版式视图中,在文档的页边距中标记批注框将显示标记元素,例如批注和所做修订。使用这些批注框可以方便地查看审阅者的修订和批注,并对其做出反应。)中。也...
标签: 电脑入门
①打开PowerPoint2013幻灯片,看到我们打开的幻灯片有批注信息。 ②单击审阅--删除按钮。准备吧批注删掉。 ③选择第一项删除,如果幻灯片页数过多,可以选择下面的两项。 ④删除完毕,从右侧任务窗格中可以看到已经没了批注。
标签: 电脑入门
本篇文章讲述了和WindowsApps文件夹有关的Win8系统常见的几个问题和解决办法。参考了百度文库,百度经验,以及软媒IT之家论坛的帖子,主要分享了删除旧版Win8应用;清理Win8应用缓存;归还 WindowsApps 权限这三个问题,感谢

经验教程

246

收藏

5
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部