c/c++语言开发共享C++学习(三十六)(C语言部分)之 链表2

测试代码笔记如下: 附: …

 

 

测试代码笔记如下:

#include<stdio.h>  #include<stdlib.h>  typedef struct node  {      int data;//数据      struct node*pre;//前驱      struct node*next;//后继  }node,*pnode;    //申请一个结点  pnode creatnode(int data)//要修改内容   传地址  {      pnode p = (node*)malloc(sizeof(node));      p->data = data;      p->pre = null;      p->next = null;      return p;  }    void  insert(pnode head, int data)  {      pnode p = creatnode(data);      //插入的位置        //头插  head->a->b  插入c      p->next = head->next;//保留后面的结点c->next=b   //这一步必须最先写      //后面三步可以换位置      if (p->next!=null) p->next->pre = p;//让b->pre=c      head->next = p;//a->next=c      p->pre = head;//c->pre=a      //中间插入  }    void delenode(pnode head, int data)  {      pnode p = head->next;//第一个节点不存数据      while (p != null)      {          if (p->data == data)          {              //找到位置              p->pre->next = p->next;              if(p->next!=null) p->next->pre = p->pre;              free(p);              break;//p已经释放  所以p不能再用于循环          }          p = p->next;      }  }    void deleallnode(pnode head)  {      pnode p = head;      while (head)//判断head不等于null      {          p = head;          head = head->next;          free(p);//释放结点      }  }    int main()  {      pnode head;      head = creatnode(0);//初始化      //循环插入节点        //删除节点)      getchar();      return 0;  }

附:

C++学习(三十六)(C语言部分)之 链表2

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/604468.html

(0)
上一篇 2021年5月12日
下一篇 2021年5月12日

精彩推荐