zoukankan      html  css  js  c++  java
  • 链表首尾节点的常规方案

    本表对基本链表处理操作分别以五种常用的定义方案给出其实现方法。这类代码用于简单的、使用内嵌链表处理代码的应用程序。

    循环,永远非空

    头插入   head->next = head;

    在x节点后插入t节点    t->next = x->next; x->next = t;

    删除x后的节点    x->next = x->next->next;

    遍历循环    t = head; do {... t = t->next; } while (t != head);

    测试是否只有一个元素    if (head->next == head)

    有头节点,尾节点为null

    初始化    head = 0;

    在x节点后插入t节点    if (x == 0) { head = t; head -> next = 0;}

                                        else {t->next = x->next; x->next = t;}

    删除x后的节点    t = x->next; x->next = t->next;

    遍历循环    for (t = head; t != 0; t = t->next)

    测试是否为空    if (head == 0)

    有哑元头节点,尾节点为null

    初始化    head = new node; head->next = 0;

    在x节点后插入t节点    t->next = x->next; x->next = t;

    删除x后的节点    t = x->next; x->next = t->next;

    遍历循环    for (t = head->next; t != 0; t = t->next)

    测试是否为空    if (head->next == 0)

                     

    有哑元头节点和尾节点

    初始化    head = new node;

                   z = new node;

                   head->next = z; z->next = z;

    在x节点后插入t节点    t->next = x->next; x->next = t;

    删除x后的节点    x->next = x->next->next;

    遍历循环    for (t = head->next; t != z; t = t->next)

    测试是否为空    if (head->next == z) 

  • 相关阅读:
    20、职责链模式
    19、命令模式
    18、桥接模式
    17、单例模式
    javascript移动端实现企业图谱总结
    前端用js模拟疫情扩散开发总结
    移动端企业图谱开发兼容性等问题踩坑
    js实现企业图谱(pc端企业图谱项目总结与踩坑分享)
    基于vue脚手架的项目打包上线(发布)方法和误区
    实现一个网页版的聊天室(类似于钉钉群)
  • 原文地址:https://www.cnblogs.com/ningjing213/p/11320829.html
Copyright © 2011-2022 走看看