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

网站侧面的虚浮代码工业产品设计效果图

网站侧面的虚浮代码,工业产品设计效果图,wordpress 个性博客,江西网站制作✨✨ 欢迎大家来到贝蒂大讲堂✨✨ #x1f388;#x1f388;养成好习惯#xff0c;先赞后看哦~#x1f388;#x1f388; 所属专栏#xff1a;数据结构与算法 贝蒂的主页#xff1a;Betty’s blog 1. 前言 前面我们学习了单链表#xff0c;它解决了顺序表中插入删除需… ✨✨ 欢迎大家来到贝蒂大讲堂✨✨ 养成好习惯先赞后看哦~ 所属专栏数据结构与算法 贝蒂的主页Betty’s blog 1. 前言 前面我们学习了单链表它解决了顺序表中插入删除需要挪动大量数据的缺点。但同时也有仍需改进的地方比如说我们有时候需要寻找某个节点的前一个节点对于单链表而言只能遍历这样就可能造成大量时间的浪费。为了解决这个问题我们就要学习今天的主角——带头双向循环链表。 2. 双向链表的功能 初始化顺序表中的数据。对顺序表进行尾插(末尾插入数据)。对顺序表进行头插(开头插入数据)。对顺序表进行头删(开头删除数据)。对顺序表进行尾删(末尾删除数据)。对顺序表就像查找数据。对顺序表数据进行修改。任意位置的删除和插入数据。打印顺序表中的数据。销毁顺序表。 3. 双向链表的定义 双向链表的定义结构体需要包含三个成员一个成员存储数值一个成员存储前一个节点的地址最后一个成员存储下一个节点的地址。 typedef int LTDataType; typedef struct DoubleList {struct DoubleList* prev;//指向前一个节点LTDataType data;struct DoubleList* next;//指向下一个节点 }DListNode;4. 双向链表的功能 4.1 初始化双向链表 在初始化双向链表时我们需要创建一个头节点也就是我们常说的哨兵位头节点。 (1) 创建头结点 DListNode* DLNodeCreat(LTDataType x) {DListNode* newnode (DListNode*)malloc(sizeof(DListNode));if (newnode NULL){perror(malloc fail:);return NULL;}newnode-prev NULL;newnode-next NULL;newnode-data x;return newnode; }(2) 初始化 初始化将头节点的前后指针都指向自己并将数值至为-1。 DListNode* InitDList() {DListNode* phead DLNodeCreat(-1);phead-prev phead;phead-next phead;return phead; }(3) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度固定创造一个节点空间复杂度为O(1)。 4.2 双向链表尾插 因为我们实现的双向链表存在头节点所以我们不需要像实现单链表一样先判断链表是否为空。 (1) 代码实现 void DListPushBack(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* tail ptr-prev;DListNode* newnode DLNodeCreat(x);tail-next newnode;newnode-prev tail;ptr-prev newnode;newnode-next ptr; }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度固定创造一个节点空间复杂度为O(1)。 4.3 双向链表头插 因为带头双向循环链表的特性即使只有头节点进行头插代码实现也是相同的。 (1) 代码实现 void DListPushFront(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* next ptr-next;DListNode* newnode DLNodeCreat(x);ptr-next newnode;newnode-prev ptr;newnode-next next;next-prev newnode; }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度固定创造一个节点空间复杂度为O(1)。 4.4 双向链表尾删 有了循环找尾节点也十分容易双向链表尾删自然并不困难。但是需要防止删除头节点。 (1) 代码实现 void DListPopBack(DListNode* ptr) {assert(ptr);assert(ptr-next ! ptr);//放置删除头节点DListNode* tail ptr-prev;DListNode* tailprev tail-prev;free(tail);tail NULL;tailprev-next ptr;ptr-prev tailprev; }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.5 双向链表头删 头删与尾删一样都需要防止删除头节点。 (1) 代码实现 void DListPopFront(DListNode* ptr) {assert(ptr);assert(ptr-next ! ptr);DListNode* phead ptr-next;DListNode* pheadnext phead-next;free(phead);ptr-next pheadnext;pheadnext-prev ptr; }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.6 双向链表查找 和单链表一样我们也可以对双向链表进行查找。如果找到就返回该节点的地址否则返回NULL。 (1) 代码实现 DListNode* DListFind(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* cur ptr-next;while (cur ! ptr){if (cur-data x){return cur;}cur cur-next;}return NULL; }(2) 复杂度分析 时间复杂度可能需要遍历整个链表时间复杂度为O(N)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.7 修改双向链表 我们可以结合双向链表的查找对双向链表进行修改。 (1) 代码实现 void DListModify(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);assert(ptr ! pos);//防止对头节点操作DListNode* cur ptr-next;while (cur ! ptr){if (cur pos){cur-data x;}cur cur-next;} }(2) 复杂度分析 时间复杂度可能需要遍历整个链表时间复杂度为O(N)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.8 双向链表指定插入数据 随机插入数据可以分为向前插入与向后插入。 (1) 向前插入 void DListInsertF(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);DListNode* newnode DLNodeCreat(x);DListNode* prev pos-prev;newnode-prev prev;newnode-next pos;prev-next newnode;pos-prev newnode; }(2) 向后插入 void DListInsertB(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);DListNode* newnode DLNodeCreat(x);DListNode* next pos-next;newnode-prev pos;newnode-next next;next-prev newnode;pos-next newnode; }(3) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.9 指定位置删除数据 任意删除也需要放置删除头节点并且因为其特点只需要一个参数就能完成该操作。 (1) 代码实现 void DListErase(DListNode* pos) {assert(pos);assert(pos ! pos-next);pos-prev-next pos - next;pos-next-prev pos-prev;free(pos);pos NULL; }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.10 打印双向链表 打印双向链表只需将循环之前的数据全部打印即可。 (1) 代码实现 void DLTPrint(DListNode* ptr) {assert(ptr);printf(guard);DListNode* cur ptr-next;while (cur ! ptr){printf(%d, cur-data);cur cur-next;}printf(\n); }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 4.11 销毁双向链表 (1) 代码实现 void DListDestroy(DListNode* ptr) {assert(ptr);DListNode* cur ptr-next;while (cur ! ptr){DListNode* next cur-next;free(cur);cur next;}free(ptr); }(2) 复杂度分析 时间复杂度没有其他额外的时间消耗时间复杂度为O(1)。空间复杂度没有额外的空间消耗空间复杂度为O(1)。 5. 完整代码 5.1 DList.h #includestdio.h #includestdlib.h #includeassert.h typedef int LTDataType; typedef struct DoubleList {struct DoubleList* prev;//指向前一个节点LTDataType data;struct DoubleList* next;//指向下一个节点 }DListNode; DListNode* InitDList();//初始化 void DListPushBack(DListNode* ptr, LTDataType x);//尾插 void DLTPrint(DListNode* ptr);//打印 void DListPushFront(DListNode* ptr, LTDataType x);//头插 void DListPopBack(DListNode* ptr);//尾删 void DListPopFront(DListNode* ptr);//头删 DListNode*DListFind(DListNode* ptr, LTDataType x);//查找 void DListModify(DListNode* ptr, DListNode* pos);//修改 void DListInsertF(DListNode* ptr, DListNode* pos, LTDataType x);//任意位置之前插入 void DListInsertB(DListNode* ptr, DListNode* pos, LTDataType x);//任意位置之后插入 void DListErase(DListNode* pos);//任意位置删除 void DListDestroy(DListNode* ptr);//销毁双向链表5.2 DList.c #includeDoubleList.h DListNode* DLNodeCreat(LTDataType x) {DListNode* newnode (DListNode*)malloc(sizeof(DListNode));if (newnode NULL){perror(malloc fail:);return NULL;}newnode-prev NULL;newnode-next NULL;newnode-data x;return newnode; } DListNode* InitDList() {DListNode* phead DLNodeCreat(-1);phead-prev phead;phead-next phead;return phead; } void DListPushBack(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* tail ptr-prev;DListNode* newnode DLNodeCreat(x);tail-next newnode;newnode-prev tail;ptr-prev newnode;newnode-next ptr; } void DListPushFront(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* next ptr-next;DListNode* newnode DLNodeCreat(x);ptr-next newnode;newnode-prev ptr;newnode-next next;next-prev newnode; } void DListPopBack(DListNode* ptr) {assert(ptr);assert(ptr-next ! ptr);//放置删除头节点DListNode* tail ptr-prev;DListNode* tailprev tail-prev;free(tail);tail NULL;tailprev-next ptr;ptr-prev tailprev; } void DListPopFront(DListNode* ptr) {assert(ptr);assert(ptr-next ! ptr);DListNode* phead ptr-next;DListNode* pheadnext phead-next;free(phead);ptr-next pheadnext;pheadnext-prev ptr; } DListNode* DListFind(DListNode* ptr, LTDataType x) {assert(ptr);DListNode* cur ptr-next;while (cur ! ptr){if (cur-data x){return cur;}cur cur-next;}return NULL; } void DListModify(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);assert(ptr ! pos);//防止对头节点操作DListNode* cur ptr-next;while (cur ! ptr){if (cur pos){cur-data x;}cur cur-next;} } void DListInsertF(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);DListNode* newnode DLNodeCreat(x);DListNode* prev pos-prev;newnode-prev prev;newnode-next pos;prev-next newnode;pos-prev newnode; } void DListInsertB(DListNode* ptr, DListNode* pos, LTDataType x) {assert(ptr);DListNode* newnode DLNodeCreat(x);DListNode* next pos-next;newnode-prev pos;newnode-next next;next-prev newnode;pos-next newnode; } void DListErase(DListNode* pos) {assert(pos);assert(pos ! pos-next);pos-prev-next pos - next;pos-next-prev pos-prev;free(pos);pos NULL; } void DLTPrint(DListNode* ptr) {assert(ptr);printf(guard);DListNode* cur ptr-next;while (cur ! ptr){printf(%d, cur-data);cur cur-next;}printf(\n); } void DListDestroy(DListNode* ptr) {assert(ptr);DListNode* cur ptr-next;while (cur ! ptr){DListNode* next cur-next;free(cur);cur next;}free(ptr); }
http://www.w-s-a.com/news/520950/

相关文章:

  • 网站栏目设计怎么写平面设计接单报价表
  • 做网站美工要学什么网站推广的方法包括
  • 哪个网站可以做笔译兼职wordpress加表单
  • 百度站内搜索 wordpress微餐饮建站费用
  • 用什么做网站的访问量统计制作手工作品
  • 微信公众号搭建网站河南卫生基层系统网站建设
  • steam账号注册网站重庆手机版建站系统哪家好
  • 中新生态城建设局门户网站wordpress云盘视频播放
  • 大型网站开发基本流程wordpress记录用户搜索
  • 云服务器安装win系统做网站wordpress边栏扩大尺寸
  • 网站开发面试自我介绍软件下载网站如何建设
  • 可以做翻译任务的网站陕西省建设厅八大员证
  • 昆明 网站推广重庆网页优化seo公司
  • 网站排名下降怎么上去设计一套app页面多少钱
  • 专门用来查找网址的网站查公司名字是否被注册
  • 自己创建网站教程河南省建设厅官方网站李学军
  • 一个网站需要多少容量怎样免费设计网站建设
  • 建设工程交易中心网站12306的网站是哪个公司做的
  • 建设网站经营范围自己给公司做网站
  • 河北省住房建设厅政务网站网络营销推广的岗位职责有哪些
  • 上海网站建设优化价格孝义做网站的公司
  • 哪个公司网站做的最好义乌 网站 制作
  • 百度站长工具综合查询wordpress 上传pdf
  • 旅游短租公寓网站建设深圳龙岗招聘网
  • 做海淘是在哪个网站网络查控系统设计方案
  • o2o网站建设代理商微信公众号开发文档
  • 网站设计课程总结关于网站备案的公告
  • 网站建设与运营意义到哪查找网站域名
  • 网站及单位网站建设情况眉县住房和城市建设局网站
  • 网站是否能够被恶意镜像wordpress占用