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) 

  • 相关阅读:
    业务线--node中间层做一个透传的项目
    JavaScript 字符串replace全局替换
    纯HTML和CSS实现点击切换
    css 清除一些默认的设置
    js异步请求方式
    VScode编辑器个性化配置
    webpack 解决跨域问题
    node.js连接MongoDB数据库,db.collection is not a function完美解决
    nodejs中安卓端的编码如何转换为中文
    深入理解js的变量提升和函数提升
  • 原文地址:https://www.cnblogs.com/ningjing213/p/11320829.html
Copyright © 2011-2022 走看看