国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

雙向鏈表插入刪除基本應用

2020-02-21 17:38:23
字體:
來源:轉載
供稿:網友

本篇文章主要介紹了雙向鏈表插入刪除基本應用,希望小編整理的相關知識和資料都對你們有所幫助。

雙鏈表其實 也沒什么 只是多了一個前置鏈而已
雙鏈表的定義


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
using namespace std;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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 (cin>>temp&&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&&num>p->data)
{
p=p->next;
}
if (numdata)
{
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
{
cout }
return head;
}
void Display(DNode *head)
{
DNode *p;
p=head;
while (NULL!=p)
{
coutdata) p=p->next;
}
cout }

?

?


#include "head.h"
int main()
{
DNode *head;
head=Creat();
Display(head);
#ifndef DEBUG
cout #endif
int insert_num;
while (cin>>insert_num&&insert_num)
{
Insert(head,insert_num);
Display(head);
}
#ifndef DEBUG
cout #endif
int delete_num;
while (cin>>delete_num&&delete_num)
{
Del(head,delete_num);
Display(head);
}
return (EXIT_SUCCESS);
}
以上就是雙向鏈表插入刪除基本應用的全部內容介紹了,希望小編整理的相關知識和資料都對你們有所幫助,更多內容請繼續關注武林技術頻道網站!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石景山区| 大竹县| 玛曲县| 车险| 额济纳旗| 高州市| 淳化县| 青冈县| 峨边| 荔浦县| 商洛市| 黄大仙区| 宜都市| 阳朔县| 海口市| 城步| 青浦区| 许昌县| 惠来县| 烟台市| 宜兴市| 城市| 弥渡县| 蚌埠市| 德钦县| 龙井市| 洛扎县| 隆尧县| 广饶县| 双鸭山市| 尤溪县| 内乡县| 龙泉市| 嵊泗县| 周宁县| 柯坪县| 简阳市| 隆化县| 七台河市| 吉首市| 鹤峰县|