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) 

  • 相关阅读:
    在这个互联网泡沫时代,施主你有何焦虑?
    对于公司最近一次技术分享的总结
    Windows系统下Redis的安装
    论语
    系统的简单和复杂是由什么决定的?
    Swift之 ? 和 !
    div模拟table,可实现左右高度同增长(html布局)
    动态添加的无缝轮播
    根据数据库名获取表和字段信息(mysql版)
    博客园更新了?
  • 原文地址:https://www.cnblogs.com/ningjing213/p/11320829.html
Copyright © 2011-2022 走看看