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

深圳建站服务中心大型网络建站公司

深圳建站服务中心,大型网络建站公司,如何去除网站外链,做cf网站前言#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.hkea.cn/news/14283537/

相关文章:

  • 网站建设如何添加歌曲怎样免费建立自己的网站
  • 北京网站制作开发公司番禺网站建设公司
  • 做兼职的网站策划书WordPress抓去微信
  • 网站建设怎么让百度搜索到跨境电商公司招聘岗位及要求
  • 买个购物网站网站怎么管理维护
  • 微网站模板建设的选择宁波市高等级公路建设指挥部网站
  • 网站开发哪个公司好金融企业如何做好网络推广
  • 电子商务网站建设精英博客登录注册
  • 网站顶部网络宣传渠道有哪些
  • 联合会网站建设wordpress 重制密码
  • 地方门户网站设计100种广告设计
  • 做视频网站的方法云南做网站多少钱
  • 营销型网站建设的优势有哪些怎么看公司网站是哪里做的
  • 毕业设计网站论文海口网站建设的开发方案
  • 如何做百度秒收录网站百度开户返点
  • h5个网站的区别成都如何寻找做网站的
  • h5企业网站源码请勿直接解析到ip否则我司不能保证您的网站能正常运行!"
  • 品牌宣传型网站有哪些房管局
  • 大连网站网页设计公司佛山市做网站的
  • 网站外链建设常用字网站建设改代码改哪些
  • 建设自己的网站需要哪些步骤两学一做材料上哪个网站找
  • 公司网站如何做二维码广州市专业网站设计
  • 邢台营销型网站制作重庆网站建设营销
  • python 网站开发 普及wordpress添加过滤器
  • 正规网站建设推荐宁波网站建设优化排名
  • 卖环保设备做哪个网站好如何网页优化
  • 个人摄影作品网站烟台网站开发制作
  • 网站seo优化心得麻豆人文化活动策划有限公司
  • 南宁网站设计seo优化流程
  • 聊城做网站的地方自己做网站背景图片