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

        //链表首尾节点的常规方案
        //示例代码片段,不能编译
    
        ///////////////////////////////////////////////////////////////
        //循环,永远非空
        head->next = head;  //头插入
        t->next = x->next; x->next = t;     //x节点后插入t节点
        x->next = x->next->next;            //删除x后的节点
    
        t=head;
        do{ t=t->next; } while(t != head)   //循环遍历
    
        if(head->next ==  head)             //测试是否只有一个元素
    
        ///////////////////////////////////////////////////////////////
        //有头节点,尾节点为null
        head = 0;                           //初始化
    
        if(x==0) {head=t; head->next = 0;}  //在x节点后插入t节点
        else { t->next=x->next; x->next=t;}
    
        t = x->next; x->next=t->next;       //删除x后的节点
        //x->next = x->next->next 表达更简单
    
        for(t=head; t!=0; t=t->next)        //遍历循环
        if(head == 0)                       //测试是否为空
    
        ///////////////////////////////////////////////////////////////
        //有哑元头节点,尾节点为null
        head = new node; head->next=0;      //初始化
        t->next = x->next; x->next = t;     //x节点后插入t节点
        t = x->next; x->next=t->next;       //删除x后的节点
        //x->next = x->next->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;
    
        t->next=x->next; x->next=t;         //在x节点后插入t节点
        x->next = x->next->next             //删除x后的节点
        for(t=head->next; t!=z; t=t->next)  //遍历循环
        if(head->next == z)                 //测试是否为空
  • 相关阅读:
    Spring+mybatis+struts框架整合的配置具体解释
    JavaScript 基础
    MySQL高可用系列之MHA(二)
    设计模式之备忘录模式
    客户管理系统之模块设计(七)
    CURL库的宏定义列表
    servlet调用的几种方式
    modprobe kvm-intel
    sql server 2008 R2 配置开启远程访问
    error: could not find library containing RSA_new
  • 原文地址:https://www.cnblogs.com/wouldguan/p/2730222.html
Copyright © 2011-2022 走看看