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

延边延吉网站建设宁波网络优化seo

延边延吉网站建设,宁波网络优化seo,专门给别人做网站,上传网站内容目录一.链表的分类二.与单链表相比三.实现增删查改1.双向循环链表结构的创建2.创建新节点3.初始化链表4.头插和尾插5.判断链表是否为空6.头删和尾删7.打印函数8.查找函数9.删除pos位置节点10.在pos前位置插入数据11.优化升级一.链表的分类 链表可有根据单向双向、有无哨兵位、…

目录

  • 一.链表的分类
    • 二.与单链表相比
      • 三.实现增删查改
        • 1.双向循环链表结构的创建
        • 2.创建新节点
        • 3.初始化链表
        • 4.头插和尾插
        • 5.判断链表是否为空
        • 6.头删和尾删
        • 7.打印函数
        • 8.查找函数
        • 9.删除pos位置节点
        • 10.在pos前位置插入数据
        • 11.优化升级

一.链表的分类

链表可有根据单向双向有无哨兵位是否循环分为八种类型,只要我们学习最简单的无头单向非循环链表以及最复杂的双向循环链表,其他的类型也就可以很好地解决了。

二.与单链表相比

与单链表相比较,单链表结构简单,一般不会单独用来存储数据,一般作为其他数据结构的子结构来使用。而双向循环链表结构复杂,但功能丰富使用便捷

三.实现增删查改

1.双向循环链表结构的创建

双向链表与之前我们剖析的单链表不同,单链表只能通过next指针向后访问导致单链表的局限性大,而双向链表不仅可以向后访问还可以向前访问。所以在创建双向链表时就需要多一个指针:

typedef int LTDataType;typedef struct ListNode
{LTDataType data;struct ListNode* next;struct ListNode* prev;
}LTNode;

2.创建新节点

在初始化和后续进行插入操作时,我们都需要创建出一个新节点进行使用,所以我们编写分装创建新节点的函数:

LTNode* CreateList(LTDataType x)
{LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));if (newnode == NULL){perror("newnode malloc");return NULL;}newnode->next = NULL;newnode->data = x;newnode->prev = NULL;return newnode;
}

3.初始化链表

因为是双向循环的链表所以哨兵位的头节点的nextprev指针都指向自己:

LTNode* LTInit()
{LTNode* phead = CreateList(-1);phead->next = phead;phead->prev = phead;return phead;}

4.头插和尾插

在双向循环的结构便利下,相较于单链表,找尾的操作会非常简单,只需要访问哨兵位的上一个节点即可。

void PushFront(LTNode* head, LTDataType x)
{assert(head);LTNode* newnode = CreateList(x);LTNode* tail=head->next;newnode->next = head->next;newnode->prev = head;tail->prev = newnode;head->next = newnode;}
void PushBack(LTNode* head, LTDataType x)
{assert(head);LTNode* newnode = CreateList(x);LTNode* tail = head->prev;tail->next = newnode;newnode->prev = tail;newnode->next = head;head->prev = newnode;
}

5.判断链表是否为空

我们在进行删除操作前,应判断此时链表是否为空,如果已经为空则不能进行删除操作。

bool Empty(LTNode* head)
{assert(head);return head->next == head;
}

6.头删和尾删

void PopFront(LTNode* head)
{assert(head);assert(!Empty(head));LTNode* tail = head->next;head->next = head->next->next;free(tail);tail = NULL;}void PophBack(LTNode* head)
{assert(head);assert(!(Empty(head)));LTNode* tail = head->prev;LTNode* tailprev = tail->prev;tailprev->next = head;head->prev = tailprev;free(tail);tail = NULL;
}

7.打印函数

在编写链表的插入删除功能时,我们常需要对代码进行测试,所以编写打印函数:

void LTPrin(LTNode* phead)
{assert(phead);printf("<=head=>");LTNode* cur = phead->next;while (cur != phead){printf("%d<=>", cur->data);cur = cur->next;}printf("\n");
}

8.查找函数

LTNode* ListFind(LTNode* head, LTDataType x)
{assert(head);LTNode* cur = head;while (cur->data != x){cur = cur->next;}return cur;}

9.删除pos位置节点

void ListErase(LTNode* pos)
{assert(pos);LTNode* tail = pos;pos->next->prev = pos->prev;pos->prev->next = pos->next;free(tail);tail = NULL;
}

10.在pos前位置插入数据

void ListInsert(LTNode* pos, LTDataType x)
{assert(pos);LTNode* prev = pos->prev;LTNode* newnode = CreateList(x);newnode->next = pos;newnode->prev = prev;pos->prev = newnode;prev->next = newnode;
}

11.优化升级

在我们编写完pos位置插入和删除后,其实对上文的头删尾删头插尾插,都可以使用这两个函数来完成:

void PushBack(LTNode* head, LTDataType x)
{assert(head);ListInsert(head, x);
}void PushFront(LTNode* head, LTDataType x)
{assert(head);ListInsert(head->next, x);
}void PopFront(LTNode* head)
{assert(head);assert(!Empty(head));ListErase(head->next);
}void PophBack(LTNode* head)
{assert(head);assert(!(Empty(head)));ListErase(head->prev);
}
http://www.hkea.cn/news/995870/

相关文章:

  • 网站建设套餐有哪些安卓在线视频嗅探app
  • 做电影网站要买什么重庆seo网站哪家好
  • 广州北京网站建设公司网站外部优化的4大重点
  • 网站建设书优化大师是干什么的
  • 优秀的网站建设公司百度指数人群画像
  • wordpress企业中文模板太原seo哪家好
  • 广东网广东网站建设网站推广方案模板
  • 网站运营知识快手seo
  • 咖啡公司网站建设策划书微信营销方式
  • 柳江区城乡住房建设局网站上海seo优化服务公司
  • 西城企业网站建设企业网站怎么优化
  • 初学者做动态网站项目例子游戏特效培训机构排名
  • 汽车类网站搭建直链平台
  • 做网站遇到的困难总结网络营销软件代理
  • 做网站登录论坛外链代发
  • 东营专业网站建设公司排行青岛谷歌优化公司
  • 公众号和网站先做哪个口碑营销的形式
  • 长沙企业建网站费用关键词搜索推广排行榜
  • 怎么做网站端口代理沧州网络推广外包公司
  • php wordpress 目录seo课程培训机构
  • 常州网站建设方案优化引流app推广软件
  • 网络营销网站建设实训网络营销步骤
  • 网站都有后台吗百度竞价开户公司
  • 秭归网站建设网站seo优化心得
  • wordpress电影网站模板seo运营
  • 公司注册网上核名业务如何终止网站排名优化怎么做
  • 网站建设伍金手指下拉2网上推广平台
  • 沧州网站建设公司翼马爱情链接
  • 计算机学了出来干嘛免费优化推广网站的软件
  • 宁波网站建设优化湖南seo优化按天付费