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

网站进度表seo排名关键词搜索结果

网站进度表,seo排名关键词搜索结果,3维网站制作技术,中国最好的网站制作Hello,好久不见,今天我们讲链表的双向链表,这是一个很厉害的链表,带头双向且循环,学了这个链表,你会发现顺序表的头插头删不再是一个麻烦问题,单链表的尾插尾删也变得简单起来了,那废…

在这里插入图片描述

Hello,好久不见,今天我们讲链表的双向链表,这是一个很厉害的链表,带头双向且循环,学了这个链表,你会发现顺序表的头插头删不再是一个麻烦问题,单链表的尾插尾删也变得简单起来了,那废话不多说,让我们开始我们的学习吧!

首先我们要了解它的物理和逻辑结构,那他们的样子是怎样的呢,首先是一个带头的,那这个难道是我们的哨兵位吗,又是双向,且循环,那让我们来画图了解它吧。

在这里插入图片描述

大致就是这样的一个形状,那我们现在需要这样的一个结构体来实现这样的功能,首先应该有一个存储数据的,就是data,然后就是得有两个指针,一个指向前面的节点,一个就是指向后面的节点,那我们就叫它们一个pre指向前面,一个next指向后面,我们来实现一下吧。

typedef int DListType;
typedef struct DList
{struct DList* pre;struct DList* next;DListType data;}DLNode;

为了方便我们写后面的时候结构体方便一点,我们先定义结构体为DLNode,这样更加方便使用。

现在我们要实现下面的各种接口来完成双链表

首先最重要的就是怎么初始化
初始化的话我们先要想想这个接口函数改的参数和返回值
因为是双向链表,所以得有一个head的头节点,这样才能链接后面的内容

初始化双链表

DLNode* DListInit();

接口函数的名字
这里我们分析首先我们得返回值为什么不是void,而是DLNode*
因为我们要在这里面创建一个头节点,这个节点我们后面都得使用,其次还有一个原因就是这样头节点就不会被销毁,当然我们也可以在外面创建一个节点,然后我们在传它的指针进去,对结构体的内容进行修改,都可以达到相同的作用,废话不多说,我们来实现吧!

DLNode* DListInit()
{DLNode* pHead = (DLNode*)malloc(sizeof(DLNode));assert(pHead);pHead->next = pHead;pHead->pre = pHead;
}

其实很简单,这里必须指针指向自己才可以,如果不这样的话,那我们的循环就不能实现了。
接下来就是怎么打印,打印很简单,我们将它这个指针传过去就行了。

打印双链表

void DListPrint(DLNode* pHead)
{assert(pHead);DLNode* cur = pHead->next;while (cur != pHead){printf("%d ", cur->data);cur = cur->next;}printf("\n");
}

打印函数的想法就是我们找head后面的那个节点,然后打印,因为头节点我们不打印,所以取cur开始,因为是循环,所以cur最后会等于pHead,这样的话就是一个循环,所以我们找下一个就行了,然后打印后更新cur。
接下来我们要创建一个节点,这样才能链接起来我们的节点。

DLNode* CreatNewNode(DListType x)
DLNode* CreatNewNode(DListType x)
{DLNode* newnode = (DLNode*)malloc(sizeof(DLNode));assert(newnode);newnode->data = x;newnode->next = NULL;newnode->pre = NULL;return newnode;
}

创造节点好了,接下来就是尾插一个节点进去,我们前面单链表尾插首先要找到尾的位置,然后再去尾插,同时要先找到尾的前一个位置,然后free尾,这样时间复杂度就是O(N),所以效率不是特别高,那我们现在因为head的位置里存放的就是尾的位置,所以不用进行查找了。我们现在来实现一下吧

双链表尾插

void DListPushBACK(DLNode* pHead, DListType x)
{assert(pHead);DLNode* newnode = CreatNewNode(x);DLNode* pre = pHead->pre;pHead->pre = newnode;newnode->next = pHead;pre->next = newnode;newnode->pre = pre;
}

其实尾插也很简单,我们这里先用一个指针保存位置,这样的话下一次插入就可以找到尾的位置,而且还不用注重顺序,这样大大的提升效率

有了尾插那就肯定有头插,一样的办法我们来实现一下

双链表的头插


void DListPushFront(DLNode* pHead, DListType x)
{assert(pHead);DLNode* newnode = CreatNewNode(x);DLNode* next = pHead->next;pHead->next = newnode;newnode->pre = pHead;newnode->next = next;next->pre = newnode;
}

有了头插这些,那肯定还有头删和尾删
那我们也来实现一下吧

尾删

void DListPopBack(DLNode* pHead)
{assert(pHead);if (pHead->next != pHead){DLNode* del = pHead->pre;del->pre->next = pHead;pHead->pre = del->pre;free(del);}
}

前面写的代码都需要测试一下,我们先来测试三个

#include"DList.h"
void test()
{DLNode* head = DListInit();DListPushBack(head, 1);DListPushBack(head, 2);DListPushBack(head, 3);DListPushBack(head, 4);DListPrint(head);DListPushFront(head, 111);DListPushFront(head, 111);DListPushFront(head, 111);DListPrint(head);DListPopBack(head);DListPopBack(head);DListPopBack(head);DListPrint(head);
}
int main()
{test();return 0;
}

发现我们的程序没有问题,我们再来实现一下头删

void DListPopFront(DLNode* pHead)
{assert(pHead);if (pHead->next != pHead){DLNode* del = pHead->next;pHead->next = del->next;del->next->pre = pHead;free(del);}
}

接下来就是双链表的查找,有了查找我们才能和在任意位置的删除和插入连用,那我们现在来实现一下吧


DLNode* DListFind(DLNode* pHead, DListType x)
{assert(pHead);DLNode* cur = pHead->next;while (cur != pHead){if (cur->data == x){return cur;}cur = cur->next;}return NULL;
}

随机插入

void DListInsert(DLNode* pos, DListType x)
{assrt(pos);DLNode* newnode = CreatNewNode(x);DLNode* pospre = pos->pre;pospre->next = newnode;newnode->pre = pospre;newnode->next = pos;pos->pre = newnode;}

也不是随机插入,是在pos位置之前插入,我们直接传pos和x就行,然后在根据之前的想法一步一步的进行插入链接就行

这里可以更新一下头插和尾插,这里就不演示了
那我们在写一个删除pos位置的函数

删除pos位置

void DListPop(DLNode* pos)
{assert(pos);DLNode* pospre = pos->pre;DLNode* posnext = pos->next;pospre->next = posnext;posnext->pre = pospre;free(pos);
}

还有一个destory我们开辟的空间,这个遍历一遍数组, 然后一个一个释放就行,但是会有问题,我们释放的时候必须看要机记住位置,可以从尾巴开始释放,用一个指针记住前面一个的位置,然后释放掉尾巴,然后更新前一个位置,用while控制一下就行了

#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
typedef int DListType;
typedef struct DList
{struct DList* pre;struct DList* next;DListType data;}DLNode;DLNode* DListInit();void DListPrint(DLNode* pHead);DLNode* CreatNewNode(DListType x);void DListPushBack(DLNode* pHead, DListType x);void DListPushFront(DLNode* pHead, DListType x);void DListPopBack(DLNode* pHead);void DListPopFront(DLNode* pHead);DLNode* DListFind(DLNode* pHead, DListType x);void DListInsert(DLNode* pos, DListType x);void DListPop(DLNode* pos);
#include"DList.h"DLNode* DListInit()
{DLNode* pHead = (DLNode*)malloc(sizeof(DLNode));pHead->next = pHead;pHead->pre = pHead;
}void DListPrint(DLNode* pHead)
{assert(pHead);DLNode* cur = pHead->next;while (cur != pHead){printf("%d ", cur->data);cur = cur->next;}printf("\n");
}DLNode* CreatNewNode(DListType x)
{DLNode* newnode = (DLNode*)malloc(sizeof(DLNode));assert(newnode);newnode->data = x;newnode->next = NULL;newnode->pre = NULL;return newnode;
}void DListPushBack(DLNode* pHead, DListType x)
{DLNode* newnode = CreatNewNode(x);DLNode* pre = pHead->pre;pHead->pre = newnode;newnode->next = pHead;pre->next = newnode;newnode->pre = pre;
}void DListPushFront(DLNode* pHead, DListType x)
{DLNode* newnode = CreatNewNode(x);DLNode* next = pHead->next;pHead->next = newnode;newnode->pre = pHead;newnode->next = next;next->pre = newnode;
}void DListPopBack(DLNode* pHead)
{assert(pHead);if (pHead->next != pHead){DLNode* del = pHead->pre;del->pre->next = pHead;pHead->pre = del->pre;free(del);}
}void DListPopFront(DLNode* pHead)
{assert(pHead);if (pHead->next != pHead){DLNode* del = pHead->next;pHead->next = del->next;del->next->pre = pHead;free(del);}
}DLNode* DListFind(DLNode* pHead, DListType x)
{assert(pHead);DLNode* cur = pHead->next;while (cur != pHead){if (cur->data == x){return cur;}cur = cur->next;}return NULL;
}void DListInsert(DLNode* pos, DListType x)
{assrt(pos);DLNode* newnode = CreatNewNode(x);DLNode* pospre = pos->pre;pospre->next = newnode;newnode->pre = pospre;newnode->next = pos;pos->pre = newnode;}void DListPop(DLNode* pos)
{assert(pos);DLNode* pospre = pos->pre;DLNode* posnext = pos->next;pospre->next = posnext;posnext->pre = pospre;free(pos);
}

谢谢大家,我们下期再见


文章转载自:
http://acuity.c7500.cn
http://relevance.c7500.cn
http://pennyroyal.c7500.cn
http://dankish.c7500.cn
http://unconsummated.c7500.cn
http://alger.c7500.cn
http://hexahedron.c7500.cn
http://howdah.c7500.cn
http://workerist.c7500.cn
http://tenantable.c7500.cn
http://frugivore.c7500.cn
http://megavolt.c7500.cn
http://couloir.c7500.cn
http://overmodest.c7500.cn
http://barely.c7500.cn
http://duckbill.c7500.cn
http://awedness.c7500.cn
http://prudential.c7500.cn
http://argument.c7500.cn
http://splenius.c7500.cn
http://laniferous.c7500.cn
http://parashot.c7500.cn
http://segregation.c7500.cn
http://septal.c7500.cn
http://moutan.c7500.cn
http://reign.c7500.cn
http://reconquer.c7500.cn
http://proxemic.c7500.cn
http://viscacha.c7500.cn
http://burin.c7500.cn
http://exhumation.c7500.cn
http://magnum.c7500.cn
http://zineb.c7500.cn
http://solubility.c7500.cn
http://roar.c7500.cn
http://golan.c7500.cn
http://chrysalid.c7500.cn
http://yewk.c7500.cn
http://beriberi.c7500.cn
http://petrologic.c7500.cn
http://inconsiderably.c7500.cn
http://tinglass.c7500.cn
http://extraordinaire.c7500.cn
http://dripple.c7500.cn
http://stupefactive.c7500.cn
http://flywheel.c7500.cn
http://hypoallergenic.c7500.cn
http://mid.c7500.cn
http://effusive.c7500.cn
http://mezz.c7500.cn
http://specify.c7500.cn
http://saltillo.c7500.cn
http://mede.c7500.cn
http://holdover.c7500.cn
http://mediator.c7500.cn
http://contrafluxion.c7500.cn
http://pacifically.c7500.cn
http://washingtonologist.c7500.cn
http://stymie.c7500.cn
http://mogaung.c7500.cn
http://roundtop.c7500.cn
http://abgrenzung.c7500.cn
http://scannable.c7500.cn
http://advertorial.c7500.cn
http://intractably.c7500.cn
http://duce.c7500.cn
http://incog.c7500.cn
http://putridity.c7500.cn
http://finnic.c7500.cn
http://omnificent.c7500.cn
http://endodontics.c7500.cn
http://worthily.c7500.cn
http://dewdrop.c7500.cn
http://cambism.c7500.cn
http://inexpungibility.c7500.cn
http://touareg.c7500.cn
http://cote.c7500.cn
http://zombiism.c7500.cn
http://unpublicized.c7500.cn
http://polje.c7500.cn
http://emperorship.c7500.cn
http://distain.c7500.cn
http://tinhorn.c7500.cn
http://maccaboy.c7500.cn
http://sw.c7500.cn
http://tefl.c7500.cn
http://rheotropism.c7500.cn
http://advection.c7500.cn
http://evidence.c7500.cn
http://bibulous.c7500.cn
http://kherson.c7500.cn
http://entrain.c7500.cn
http://fooling.c7500.cn
http://cantonese.c7500.cn
http://toneless.c7500.cn
http://microplankton.c7500.cn
http://ringhals.c7500.cn
http://recomposition.c7500.cn
http://eradiculose.c7500.cn
http://semanticist.c7500.cn
http://www.zhongyajixie.com/news/85984.html

相关文章:

  • 做暧小说在线观看网站产品线上营销推广方案
  • 有专门做市场分析的网站么全球十大网站排名
  • wordpress怎么css志鸿优化设计答案网
  • 建设银行网站用户注册不了职业培训热门行业
  • 2018年主流网站开发语言推广app网站
  • 房产网站怎么做才能吸引人聚名网域名注册
  • PHP网站开发技术期末作品软文代写费用
  • 哪里学网站开发好在线优化工具
  • 男女做羞羞事动画网站免费深圳网络seo推广
  • 深圳公司建立网站长沙网站推广有哪些啊
  • 国外做美食的网站如何设计网站的首页
  • 学做视频t的网站推广资源seo
  • 网站如何做seowindows优化大师怎么使用
  • 建设网站观澜百度收录关键词
  • 海纳企业网站管理系统鹤壁seo
  • 广州公司注册地址可以是住宅吗深圳百度推广seo公司
  • 定制网站建设服务关键词优化技巧
  • 潜山做网站星乐seo网站关键词排名优化
  • 各类东莞微信网站建设抖音关键词排名优化软件
  • 景德镇网站维护免费网站建站2773
  • 阿里巴巴做网站联系人厨师培训
  • 做网站前台需要什么技能sem培训班
  • 美味西式餐饮美食网站模板星链seo管理
  • 手机网站建设多少钿企拓客app骗局
  • 免费做相册视频网站苏州网站建设优化
  • 谷歌网站收录入口网络推广网络营销软件
  • 南通网站建设教程爱站网 关键词挖掘工具站
  • 做网站的哪里便宜网址大全百度
  • 新昌县住房和城乡建设局网站百度推广电话号码
  • 北京制作网站的基本流程衡水网站优化推广