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

中国做的比较好的网站设计公司有哪些学it什么培训机构好

中国做的比较好的网站设计公司有哪些,学it什么培训机构好,小学毕业个人主页设计,团购网站怎么做文章目录 1. 双向带头循环链表的结构2. 相关操作2.1 创建节点2.2 尾插2.3 头插2.4 打印2.5 尾删2.6 头删2.7 查找2.8 指定位置前/后插入2.9 删除指定位置的节点2.10 删除指定位置后的节点2.11 销毁链表 3.顺序表与链表区别 1. 双向带头循环链表的结构 与单链表不同的是&#xf…

文章目录

  • 1. 双向带头循环链表的结构
  • 2. 相关操作
    • 2.1 创建节点
    • 2.2 尾插
    • 2.3 头插
    • 2.4 打印
    • 2.5 尾删
    • 2.6 头删
    • 2.7 查找
    • 2.8 指定位置前/后插入
    • 2.9 删除指定位置的节点
    • 2.10 删除指定位置后的节点
    • 2.11 销毁链表
  • 3.顺序表与链表区别

在这里插入图片描述

1. 双向带头循环链表的结构

在这里插入图片描述
与单链表不同的是:

  • 双向链表有一个“哨兵位”作为单独的头节点
  • 每个节点都可以指向其前驱和后继节点
  • 链表是循环的

带头链表里的头节点,实际为“哨兵位”,哨兵位节点不存储任何有效元素,只是站在这里“放哨的”
“哨兵位”存在的意义:遍历循环链表避免死循环。

typedef int ListDataType;
typedef struct List
{ListDataType data;struct List* prev;//指向前驱节点struct List* next;//指向后继节点
}List;

2. 相关操作

2.1 创建节点

在这里插入图片描述

  • 创建的每个节点应该自己成环
List* BuyNode(ListDataType x)
{List* newnode = (List*)malloc(sizeof(List));if (newnode == NULL){perror(malloc);return NULL;}newnode->data = x;newnode->next = newnode;newnode->prev = newnode;
}

创建哨兵位:

int main()
{//哨兵位List* head = BuyNode(-1);return 0;
}

2.2 尾插

在这里插入图片描述

void ListPushBack(List* phead, ListDataType x)
{assert(phead);List* newnode = BuyNode(x);newnode->next = phead;newnode->prev = phead->prev;//尾节点指向新节点phead->prev->next = newnode;phead->prev = newnode;
}

2.3 头插

在这里插入图片描述

void ListPushFront(List* phead, ListDataType x)
{assert(phead);List* newnode = BuyNode(x);newnode->next = phead->next;newnode->prev = phead;phead->next = newnode;//只有头节点时,就是头节点的prevphead->next->prev = newnode;
}

2.4 打印

由于是循环链表,所以循环停止的条件应该是:cur != head

void ListPrint(List* phead)
{assert(phead);List* cur = phead->next;while (cur != phead){printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");
}

在这里插入图片描述

2.5 尾删

  • 不能没有节点
  • 尾节点的前驱节点指向头节点
  • 头节点指向尾节点的前驱节点
  • 释放尾节点
void ListPopBack(List* phead)
{assert(phead);//只有头节点assert(phead->next != phead);List* del = phead->prev;del->prev->next = phead;phead->prev = del->prev;free(del);
}

2.6 头删

  • 不能没有节点
  • 待删除节点的后继节点的prev指向头节点
  • 头节点指向待删除节点的后继节点
void ListPopFront(List* phead)
{assert(phead);assert(phead->next != phead);List* del = phead->next;del->next->prev = phead;phead->next = del->next;free(del);
}

2.7 查找

List* ListFind(List* phead, ListDataType x)
{assert(phead);assert(phead->next != phead);List* cur = phead->next;while (cur != phead){if (cur->data == x){return cur;}cur = cur->next;}return NULL;
}

2.8 指定位置前/后插入

  • 将新节点与指定位置相连即可

指定位置前

void ListPosFrontInsert(List* pos, ListDataType x)
{assert(pos);List* newnode = BuyNode(x);List* prev = pos->prev;newnode->prev = prev;newnode->next = pos;prev->next = newnode;pos->prev = newnode;
}

指定位置后

void ListPosBackInsert(List* pos, ListDataType x)
{assert(pos);List* newnode = BuyNode(x);List* next = pos->next;newnode->next = next;newnode->prev = pos;next->prev = newnode;pos->next = newnode;
}

2.9 删除指定位置的节点

  • 将指定位置的前驱节点、后继节点连接即可
void ListPosDel(List* pos)
{assert(pos);List* prev = pos->prev;List* next = pos->next;prev->next = next;next->prev = prev;free(pos);pos = NULL;
}

2.10 删除指定位置后的节点

  • 若指定位置是尾节点,则应该执行头删
void ListPosAfterDel(List* phead, List* pos)
{assert(phead);assert(pos);if (pos->next == phead){ListPopFront(phead);}else{List* del = pos->next;del->next->prev = pos;pos->next = del->next;free(del);}
}

2.11 销毁链表

  • 此接口的参数是一级指针,所以并不能将哨兵位销毁;因此需要再调用处再将哨兵位置为空
void ListDestroy(List* phead)
{assert(phead);assert(phead->next != phead);List* cur = phead->next;while (cur != phead){List* next = cur->next;free(cur);cur = next;}cur = NULL;free(phead);phead = NULL;
}

在这里插入图片描述

3.顺序表与链表区别

不同点顺序表链表
存储空间上物理上一定连续逻辑上连续,物理上不一定连续
随机访问O(1)O(N)
任意位置插入或删除可能需要搬运元素,效率低O(N)只需修改指针指向
插入动态顺序表,空间不够需要扩容没有容量的概念
应用场景元素高效存储,频繁访问任意位置频繁插入/删除
缓存利用率
http://www.zhongyajixie.com/news/66626.html

相关文章:

  • 宁波做企业网站公司做网络销售感觉自己是骗子
  • 网站建设58久久seo正规吗
  • xps13适合网站开发吗百度seo插件
  • 网站建设公司广州增城深圳高端网站建设公司
  • 通州网站建设站开发评价百度快照排名
  • 正规软件开发培训机构青岛seo推广公司
  • 做调查表的网站深圳优化怎么做搜索
  • 中企网站建设免费p站推广网站入口
  • 做网站的费用考研培训班哪个机构比较好
  • 高端制造优化合作平台
  • 关于大创做网站的项目计划书网络广告营销的概念
  • 网站内容设计主要包括百度链接收录
  • 狭义的网络营销是什么搜索引擎优化涉及的内容
  • 广州白云区最新疫情网络推广与优化
  • 网站开发的概要设计模板seo综合查询网站
  • 企业形象包装公司短视频seo询盘获客系统
  • 重庆seo多少钱seo排名计费系统
  • 江西高端网站定制广东网站seo营销
  • 免费简历模板制作网站湖南网站营销推广
  • 网站会对特殊的ip做跳转百度快速收录账号购买
  • 自己建设网站服务器在线制作网页网站
  • 小程序网站做多大尺寸深圳营销推广引流公司
  • 国外购物网站app谷歌收录查询
  • 小企业如何优化网站建设网络上哪里可以做推广
  • 交互设计就业方向和前景seo百度百科
  • 网站建设安排哪些平台可以打小广告
  • 郑州做网站网站技术制作
  • 影视传媒网站源码网址
  • 树莓派wordpress建站aso优化教程
  • wordpress改网站地址网络营销策划方案框架