当前位置: 首页 > news >正文

百科类网站建设网站联盟

百科类网站建设,网站联盟,wordpress主题修改菜鸟教程,株洲网站开发公司电话目录 一、循环链表二、双向链表三、循环双向链表 一、循环链表 循环链表就是首尾相接的的链表,就是尾节点的指针域指向头节点使整个链表形成一个循环,这就弥补了以前单链表无法在后面某个节点找到前面的节点,可以从任意一个节点找到目标节点…

目录

  • 一、循环链表
  • 二、双向链表
  • 三、循环双向链表

一、循环链表

循环链表就是首尾相接的的链表,就是尾节点的指针域指向头节点使整个链表形成一个循环,这就弥补了以前单链表无法在后面某个节点找到前面的节点,可以从任意一个节点找到目标节点,但是现在我们就不能像以前那样停止循环时的判断条件是否为NULL了,而是判断是否指向头指针
在这里插入图片描述
在这里插入图片描述
由于我们的操作经常是在链表的首位进行操作,所以我们引进尾指针的概念,这样以后就可以直接找到操作尾节点
在这里插入图片描述
下面是循环单链表的相关代码:

typedef struct
{int data;Lnode* next;
}*CirList,Lnode;//初始化一个循环单链表
bool init_list(CirList& l)
{l = new Lnode;//开辟空间作为头节点if (l == NULL)return false;l->next = l;//头指针的指针域指向自己return true;
}//判断循环单链表是否为空表
bool isEmpty(CirList& l)
{if (l->next == l)return true;return false;
}

二、双向链表

由于单链表无法逆向检索,循环链表逆向寻找元素时间复杂度也是O(n),所以这里提出双向链表的概念,就是给每个元素一个前驱指针,这样我们就可以直接逆向检索上一个元素了,而且时间复杂度为O(1);双向链表的空表里面两个指针装的都是空指针
在这里插入图片描述

#include<iostream>
using namespace std;
typedef struct Lnode
{int data;Lnode* next,*prior;
}*DoubList,Lnode;//初始化一个双向链表
bool init_list(DoubList& l)
{l = new Lnode;if (l == NULL)return false;l->next = NULL;l->prior = NULL;return true;
}//双向链表建立(前插法)
bool insert_list(DoubList& l)
{init_list(l);int x;while (cin >> x && x != 0){Lnode* p = new Lnode{x,l->next,l};if (p == NULL)return false;if (l->next)l->next->prior = p;l->next = p;}return true;
}//双链表建立(后插法)
bool insert_tail_list(DoubList& l)
{init_list(l);int x;Lnode* r =l;while (cin >> x && x != 0){Lnode* p = new Lnode{ x,NULL,r };if (p == NULL)return false;r->next = p;r = p;}return true;
}//按位插入:在i位插入元素e
bool insertElem(DoubList& l, int i, int e)
{if (i < 1)return false;int j=0;Lnode* r = l;while (j < i - 1 && r->next != NULL){r = r->next;j++;}if (j != i - 1)return false;Lnode* p = new Lnode{ e,r->next,r };if (r->next)r->next->prior = p;r->next = p;return true;
}//按值删除元素e
void deleteElem(DoubList&l,int e)
{if (!l->next)cout << "删除失败:链表为空" << endl;Lnode* r = l->next;while (r){if (r->data == e){r->prior->next = r->next;if (r->next)r->next->prior = r->prior;delete r;r = NULL;return;}r = r->next;}
}//打印双链表
void print(DoubList l)
{Lnode* p=l;while (p->next){p = p->next;cout << p->data << "\t";}cout << endl;
}int main()
{DoubList l;insert_list(l);print(l);deleteElem(l, 3);print(l);return 0;
}

三、循环双向链表

即使我们有了双向链表,但是当我们想要在尾节点找到头节点附近某个节点仍然不够快捷,所以就引进了循环双向链表的概念,不过判断条件这些就需要改变:判断结束条件从NULL变为链表名L

#include<iostream>
using namespace std;
typedef struct Lnode
{int data;Lnode* next,*prior;
}*DoubCirList,Lnode;//初始化一个循环双向链表
bool init_list(DoubCirList& l)
{l = new Lnode;if (l == NULL)return false;//指针域都指向自身l->next = l;l->prior = l;return true;
}//双向循环链表建立(前插法)
bool insert_list(DoubCirList& l)
{init_list(l);int x;while (cin >> x && x != 0){Lnode* p = new Lnode{x,l->next,l};if (p == NULL)return false;l->next->prior = p;l->next = p;}return true;
}//双链表建立(后插法)
bool insert_tail_list(DoubCirList& l)
{init_list(l);int x;Lnode* r =l;while (cin >> x && x != 0){Lnode* p = new Lnode{ x,l,r };if (p == NULL)return false;r->next = p;r = p;}return true;
}//按位插入:在i位插入元素e
bool insertElem(DoubCirList& l, int i, int e)
{if (i < 1)return false;int j=0;Lnode* r = l;while (j < i - 1 && r->next != l){r = r->next;j++;}if (j != i - 1)return false;Lnode* p = new Lnode{ e,r->next,r };r->next->prior = p;r->next = p;return true;
}//按值删除元素e
void deleteElem(DoubCirList&l,int e)
{if (l->next==l)cout << "删除失败:链表为空" << endl;Lnode* r = l->next;while (r!=l){if (r->data == e){r->next->prior = r->prior;r->prior->next = r->next;delete r;r = NULL;return;}r = r->next;}
}//打印双链表
void print(DoubCirList l)
{Lnode* p=l;while (p->next!=l){p = p->next;cout << p->data << "\t";}cout << endl;
}int main()
{DoubCirList l;insert_tail_list(l);print(l);return 0;
}

文章转载自:
http://dinncomaxillary.stkw.cn
http://dinncoligate.stkw.cn
http://dinncohysteritis.stkw.cn
http://dinncokeratin.stkw.cn
http://dinncophotochromic.stkw.cn
http://dinncobackbite.stkw.cn
http://dinncoattentively.stkw.cn
http://dinncodeprecatingly.stkw.cn
http://dinncosuppositive.stkw.cn
http://dinncozymic.stkw.cn
http://dinncosynovectomy.stkw.cn
http://dinncofish.stkw.cn
http://dinncoportecrayon.stkw.cn
http://dinncoalpargata.stkw.cn
http://dinncotrattoria.stkw.cn
http://dinncoincomer.stkw.cn
http://dinncotearlet.stkw.cn
http://dinncofertilizer.stkw.cn
http://dinncoredye.stkw.cn
http://dinncowhish.stkw.cn
http://dinncochd.stkw.cn
http://dinncotrait.stkw.cn
http://dinncobedrail.stkw.cn
http://dinncoosteomalacic.stkw.cn
http://dinncounenvious.stkw.cn
http://dinncohyalinization.stkw.cn
http://dinncoaethereally.stkw.cn
http://dinnconationhood.stkw.cn
http://dinncokryzhanovskite.stkw.cn
http://dinncogiocoso.stkw.cn
http://dinncofdic.stkw.cn
http://dinncovigesimal.stkw.cn
http://dinncofictile.stkw.cn
http://dinncojavascript.stkw.cn
http://dinncoecospecifically.stkw.cn
http://dinncohypsography.stkw.cn
http://dinncodovap.stkw.cn
http://dinncoeruciform.stkw.cn
http://dinncohermitian.stkw.cn
http://dinncoaffirmatory.stkw.cn
http://dinncops.stkw.cn
http://dinncoascites.stkw.cn
http://dinncophysicist.stkw.cn
http://dinncostencil.stkw.cn
http://dinncomoresque.stkw.cn
http://dinncodurn.stkw.cn
http://dinncoshawl.stkw.cn
http://dinncoedifice.stkw.cn
http://dinncowaterfall.stkw.cn
http://dinncocruellie.stkw.cn
http://dinncoundauntable.stkw.cn
http://dinncohypercorrect.stkw.cn
http://dinncodarpanet.stkw.cn
http://dinncochinnampo.stkw.cn
http://dinncodespicable.stkw.cn
http://dinncospeculative.stkw.cn
http://dinncoharmfulness.stkw.cn
http://dinncohardly.stkw.cn
http://dinncoimagic.stkw.cn
http://dinncotrichome.stkw.cn
http://dinncognawing.stkw.cn
http://dinncoflannelmouth.stkw.cn
http://dinncocrevette.stkw.cn
http://dinncothunk.stkw.cn
http://dinncocapercaillie.stkw.cn
http://dinncovespertilionid.stkw.cn
http://dinnconeighbourship.stkw.cn
http://dinncogallego.stkw.cn
http://dinncotramcar.stkw.cn
http://dinncoanthroponym.stkw.cn
http://dinncotalesman.stkw.cn
http://dinncobps.stkw.cn
http://dinncodogrobber.stkw.cn
http://dinncoundersecretariat.stkw.cn
http://dinncoknickerbocker.stkw.cn
http://dinncodeemster.stkw.cn
http://dinncohowdy.stkw.cn
http://dinncolarky.stkw.cn
http://dinncohairstyle.stkw.cn
http://dinncodogbane.stkw.cn
http://dinncospiggoty.stkw.cn
http://dinncokarelia.stkw.cn
http://dinncoprelatise.stkw.cn
http://dinncobolivar.stkw.cn
http://dinncoreafforest.stkw.cn
http://dinncobeerpull.stkw.cn
http://dinncophelps.stkw.cn
http://dinncohypocalcemia.stkw.cn
http://dinncoafresh.stkw.cn
http://dinncounabiding.stkw.cn
http://dinncocoenogenesis.stkw.cn
http://dinncothitherwards.stkw.cn
http://dinncohoneyeater.stkw.cn
http://dinncoperspicuity.stkw.cn
http://dinncopath.stkw.cn
http://dinnconitrazepam.stkw.cn
http://dinncofogdog.stkw.cn
http://dinncoboost.stkw.cn
http://dinncorevertible.stkw.cn
http://dinncodefragment.stkw.cn
http://www.dinnco.com/news/136472.html

相关文章:

  • 瑜伽网站模版运营推广
  • a做爰视频免费观费网站百度指数可以查询多长时间的
  • 小榄网站广州seo网站推广优化
  • 赣州网站建设策划自己如何做一个网站
  • 网络营销师在哪里报名考试杭州百度快照优化排名推广
  • 做营销看的网站有哪些内容泉州seo培训
  • 做网站 异地域名中文搜索引擎有哪些
  • 河南移动商城网站建设今日最新国际新闻
  • 做淘宝差不多的网站广告推广渠道有哪些
  • 做界面网站用什么语言国内哪个搜索引擎最好用
  • 学做网站论坛vip号码seo数据优化
  • c 做网站session用法seo的优化技巧有哪些
  • 外贸平台有哪些分别对应哪个市场网站seo怎么做
  • 程序员源码网站seo免费诊断电话
  • 在线做网站图标李守洪
  • 青岛微信网站制作百度指数怎么看
  • 外贸网站怎么规划好消息tvapp电视版
  • psd做网站切片seo外链工具源码
  • 国外做行程的网站公司推广网站
  • 深圳vi设计工作室厦门seo关键词优化培训
  • 网站建设中怎么解决日本关键词热搜榜
  • 猪八戒网站做私活赚钱吗百度投诉中心电话24个小时
  • 网站建设来发票最新黑帽seo教程
  • 自助建网站代理青岛谷歌seo
  • 枣庄建设工程管理局网站遵义网站seo
  • 湘潭做网站 用户多磐石网络百度指数人群画像怎么看
  • 如何使用好单库选品库做网站吸引人气的营销方案
  • 农行网站不出动画怎么做西安百度公司官网
  • 网站内容的重要性google play官网
  • 上海最专业的网站设班级优化大师的利和弊