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

织梦cms 学校网站模板网站建设中的问题

织梦cms 学校网站模板,网站建设中的问题,建筑设计参考网站,电商网站后台报价前言#xff1a; 前面我们已经学习了单链表的结构及其功能特点#xff0c;也了解了单链表在实现一些功能时出现的一些缺点#xff0c;比如在删除某个节点前面一个节点时就需要再开一个变量来存放前面一个节点的信息#xff0c;这样就显得不灵活#xff0c;为了使链表实现功…前言 前面我们已经学习了单链表的结构及其功能特点也了解了单链表在实现一些功能时出现的一些缺点比如在删除某个节点前面一个节点时就需要再开一个变量来存放前面一个节点的信息这样就显得不灵活为了使链表实现功能更加灵活我给来介绍带头双向循环链表这种链表可以看成是单链表的升级版。 什么是带头双向循环链表 带头双向循环链表是一种常见的链表数据结构它是由若干个结点组成的链式数据结构每个结点包含两个指针分别指向前一个结点和后一个结点。与普通的单向链表只能单向遍历不同在双向循环链表中可以使用前后两个方向进行遍历。 带头双向循环链表的优点 带头链表意味着在链表头部添加一个空的头结点这个头结点不包含数据仅包含指向链表首尾结点的指针它主要作用是简化链表的操作。在插入、删除、查找等操作时可以直接从头结点开始操作无需特殊处理首尾结点。 双向循环意味着链表的每一个节点都可以随意的找到上一个节点以及下一个节点并且头节点的前驱指针指向尾节点尾节点的后驱指针指向头节点这样整个链表就形成了一个环状结构可以任意方向遍历整个链表。 由于带头双向循环链表具有链表的优点同时又兼具循环队列的特点因此在实际应用中被广泛使用。比如在实现 LRU 缓存淘汰算法、模拟双向队列等场景中都有使用。 代码实现 DList.h头文件 各种功能函数的声明以及数据的定义 #includestdio.h #includestdlib.h #includeassert.h// 带头双向循环链表增删查改实现 typedef int LTDataType; typedef struct ListNode {LTDataType _data;struct ListNode* _next;struct ListNode* _prev; }ListNode;// 创建返回链表的头结点. ListNode* ListCreate(); // 双向链表销毁 void ListDestory(ListNode* phead); // 双向链表打印 void ListPrint(ListNode* phead); // 双向链表尾插 void ListPushBack(ListNode* phead, LTDataType x); // 双向链表尾删 void ListPopBack(ListNode* phead); // 双向链表头插 void ListPushFront(ListNode* phead, LTDataType x); // 双向链表头删 void ListPopFront(ListNode* phead); // 双向链表查找 ListNode* ListFind(ListNode* phead, LTDataType x); // 双向链表在pos的前面进行插入 void ListInsert(ListNode* pos, LTDataType x); // 双向链表删除pos位置的节点 void ListErase(ListNode* pos);DList.c文件 各种功能函数的具体实现细节 #includeDList.h// 创建返回链表的头结点. ListNode* ListCreate() {ListNode* NewList (ListNode*) malloc(sizeof(ListNode));if (NewList NULL) {perror(malloc: fail);}NewList-_data -1;NewList-_prev NewList;NewList-_next NewList;return NewList; }//创造节点 static ListNode* CreatNode(LTDataType x) {ListNode* newnode (ListNode*)malloc(sizeof(ListNode));if (newnode NULL) {perror(malloc:fail);}newnode-_data x;newnode-_next newnode;newnode-_prev newnode;return newnode; }// 双向链表销毁 void ListDestory(ListNode* phead) {assert(phead);ListNode* cur phead;cur cur-_next;while (cur!phead) {ListNode* temp cur-_next;cur-_prev-_next cur-_next;cur-_next-_prev cur-_prev;free(cur);cur temp;}free(cur);cur NULL; }// 双向链表打印 void ListPrint(ListNode* phead) {assert(phead);ListNode* cur phead-_next;printf(%d, phead-_data);while (cur! phead) {printf( %d , cur-_data);cur cur-_next;}printf(%d\n, phead-_data); }// 双向链表尾插 void ListPushBack(ListNode* phead, LTDataType x) {assert(phead);ListNode* newnode CreatNode(x);ListNode* tail phead-_prev;tail-_next newnode;newnode-_prev tail;newnode-_next phead;phead-_prev newnode; } // 双向链表尾删 void ListPopBack(ListNode* phead) {assert(phead(phead-_next!phead));ListNode* tail phead-_prev;phead-_prev tail-_prev;tail-_prev-_next phead;free(tail);tail NULL; } // 双向链表头插 void ListPushFront(ListNode* phead, LTDataType x) {assert(phead);ListNode* newnode CreatNode(x);phead-_next-_prev newnode;newnode-_next phead-_next;newnode-_prev phead;phead-_next newnode; }// 双向链表头删 void ListPopFront(ListNode* phead) {assert(phead(phead-_next!phead));ListNode* head phead-_next;phead-_next-_next-_prev phead;phead-_next phead-_next-_next;free(head);head NULL; }// 双向链表查找 ListNode* ListFind(ListNode* phead, LTDataType x) {assert(phead (phead-_next ! phead));//ListNode* newnode CreatNode(x);ListNode* cur phead-_next;while (cur ! phead) {if (cur-_data x) {return cur;}cur cur-_next;}return NULL; }// 双向链表在pos的前面进行插入 void ListInsert(ListNode* pos, LTDataType x) {assert(pos);ListNode* newnode CreatNode(x);pos-_prev-_next newnode;newnode-_prev pos-_prev;newnode-_next pos;pos-_prev newnode; } // 双向链表删除pos位置的节点 void ListErase(ListNode* pos) {assert(pos(pos-_next!pos));ListNode* temp pos;pos-_prev-_next pos-_next;pos-_next-_prev pos-_prev;free(temp);temp NULL; }test.c测试文件 分块测试各个部分的功能 #includeDList.hvoid test1()//测试尾插、尾删 {// 创建返回链表的头结点.ListNode* pheadNULL;phead ListCreate();ListPushBack(phead, 1);//尾插ListPushBack(phead, 2);ListPushBack(phead, 3);ListPrint(phead);printf(尾删\n);ListPopBack(phead);//尾删ListPrint(phead);printf(尾删\n);ListPopBack(phead);//尾删ListPrint(phead);//ListPopBack(phead);//ListPrint(phead);ListDestory(phead);//销毁链表 }void test2()//测试头插、头删 {// 创建返回链表的头结点.ListNode* phead NULL;phead ListCreate();ListPushFront(phead, 1);//头插头删ListPushFront(phead, 2);ListPushFront(phead, 3);ListPrint(phead);printf(头删\n);ListPopFront(phead);ListPrint(phead);printf(头删\n);ListPopFront(phead);//ListPopFront(phead);//ListPopFront(phead);//ListPopFront(phead);ListPrint(phead);ListDestory(phead);} void test3()//测试查找随机位置插入随机位置删除 {// 创建返回链表的头结点.ListNode* phead NULL;phead ListCreate();//初始化链表数据 1 2 3 4 5ListPushFront(phead, 1);ListPushFront(phead, 2);ListPushFront(phead, 3);ListPushFront(phead, 4);ListPushFront(phead, 5);ListPrint(phead);//ListNode* targetnode ListFind(phead, 5);ListNode* targetnode ListFind(phead, 4);if (targetnode NULL) {//没有找到printf(没有找到\n);}else {printf(找到%d了\n,targetnode-_data);/*ListErase(targetnode);printf(删除这个节点\n);*/ListInsert(targetnode, 10);//在目标节点前面插入printf(在这个节点插入一个数\n);ListPrint(phead);}ListNode* targetnode2 ListFind(phead, 4);if (targetnode2 NULL) {//没有找到printf(没有找到\n);}else {printf(找到%d了\n, targetnode2-_data);ListErase(targetnode);printf(删除这个节点\n);ListPrint(phead);}//ListPopFront(phead);//ListPrint(phead);ListDestory(phead);phead NULL; }int main() {test1();//test2();//test3();return 0; }test1运行结果 test2运行结果 test3运行结果
http://www.w-s-a.com/news/400575/

相关文章:

  • 山东济南网站建设公司制作wordpress模板教程视频教程
  • 档案网站的建设怎样更新网站内容
  • 网站开发项目规划房地产趋势与前景
  • 网上网站开发这个百度的网站怎么做的
  • 南昌市建设局官方网站网龙网络公司地址
  • 自助建站平台源码公司网站谁负责做
  • 旅游的网站怎么做网站流量的主要来源有
  • 高新网站设计找哪家网络科技有限公司实习报告
  • 专业网站建设质量推荐网络销售是做网站推广
  • 旅游网站建设模板wordpress最好最全的教程
  • 网站站长在哪登陆后台网站设计一年费用
  • 济南比较好的网站建设公司邢台信息网123
  • 双峰网站建设漳州优化网站建设
  • app和网站开发的成本虚拟主机是啥
  • 想做一个自己设计公司的网站怎么做的销售培训
  • 南昌网站建设模板合作凡客app哪去了
  • 有免费做网站的吗建设互联网站
  • 北京市保障房建设投资中心网站淄博哪个网站做房屋出赁好
  • 如何做网站的优化网站开发怎么收费
  • 网站的关键词怎么选择2345实用查询
  • 免费的制作网站做图剪片文案网站app接单
  • 中国有多少网站有多少域名上海网站建设网页制作邢台
  • 网站 数据报表如何做室内设计联盟官方网站入口
  • 怎样建设网站论文合肥做网站的软件公司
  • 收款后自动发货的网站是怎么做的怎么看网站后台网页尺寸
  • 谷歌seo引擎优化宁波seo关键词
  • 外贸网站建设需要注意什么seo课程
  • 做信息图网站网站建设的软件介绍
  • 网站开发语言数据库有几种魏县审批建设的网站
  • 北京公司网站建设推荐海口建设