当前位置: 首页 > news >正文

网站定制成exe华容县住房和城乡建设局网站

网站定制成exe,华容县住房和城乡建设局网站,wordpress清理过期文件,企业网站mp4怎么处理本文主要探讨单链表与双链表相关知识。 linux内核链表(include/linux/list.h) 内核链表中纯链表封装,纯链表的各种操作函数(节点创建、插入、删除、遍历),纯链表内嵌在驱动结构体中,实现驱动的创建、插入、删除、遍历等 单链表 单链表链表头插…

本文主要探讨单链表与双链表相关知识。

linux内核链表(include/linux/list.h)
        内核链表中纯链表封装,纯链表的各种操作函数(节点创建、插入、删除、遍历······),纯链表内嵌在驱动结构体中,实现驱动的创建、插入、删除、遍历等

单链表 

        单链表链表头插入节点,尾插入节点,删除节点,逆序

代码示例:

#include <stdio.h>
#include <stdlib.h>struct node
{int data;struct node *next;
};//创建节点
struct node * create_node(int data)
{struct node *p = (struct node *)malloc(sizeof(struct node));if(p == NULL){printf("malloc error\n");return NULL;}p->data = data;p->next = NULL;return p;
}//头部插入节点
void insert_head(struct node *phead,struct node *new)
{struct node *p = phead;if(p == NULL)exit(0);new->next = p->next;p->next = new;(phead->data)++;        //头节点存储节点数量
}//尾部插入
void insert_tail(struct node *phead,struct node *new)
{struct node *p = phead;if(p == NULL)exit(0);while(p->next != NULL){p = p->next;}p->next = new;(phead->data)++;        //头节点存储节点数量
}//遍历链表
void printf_link(struct node *phead)
{if(phead == NULL)exit(0);struct node *p = phead;printf("num of struct : %d \n",p->data);while(p->next != NULL){p = p->next;printf("struct data : %d\n",p->data);}
}//删除节点
int  delete_node(struct node *phead,int data)
{if(phead == NULL)exit(-1);struct node *p = phead;struct node *prev = NULL;while(p->next != NULL){prev = p;p = p->next;if(p->data == data){if(p->next != NULL){prev->next = p->next;   //其他节点free(p);}else{prev->next = NULL;      //尾节点free(p);}(phead->data)--;return 0;}}printf("have no data\n");return -1;
}//链表逆序
void reserve_link(struct node *phead)
{if(phead == NULL)exit(-1);struct node *p = phead->next;struct node *back = NULL;struct node *prev = NULL;if(p->next == NULL || p == NULL)        //只有一个节点,不逆序return ;while(p->next != NULL)                  //两个及两个以上节点{back = p->next;                 //保存链表的下一个节点,由于头插逆序法插入节点与后面节点断开if(p == phead->next)            //第一个节点指向NULL作为逆序首节点{p->next = NULL;}else{p->next = phead->next;}phead->next = p;p = back;}insert_head(phead,p);   //最后一个节点插入到链表,由于最后一个节点指向NULL,while判断失效(phead->data)--;        //头插最后一个节点时,默认新增一个节点
}int main()
{//创建头节点struct node *head = create_node(0);//头部插入节点insert_head(head,create_node(1));insert_head(head,create_node(2));insert_head(head,create_node(3));insert_head(head,create_node(4));insert_head(head,create_node(5));//尾部插入节点insert_tail(head,create_node(1));insert_tail(head,create_node(2));insert_tail(head,create_node(3));insert_tail(head,create_node(4));insert_tail(head,create_node(5));//遍历节点printf_link(head);//删除节点delete_node(head,5);delete_node(head,5);delete_node(head,4);//遍历节点printf_link(head);//链表逆序reserve_link(head);//遍历节点printf_link(head);return 0;
}

结果示例:

双链表

        双链表尾插入,头插入,删除节点,前向遍历,后向遍历 

代码示例:

#include <stdio.h>
#include <stdlib.h>struct node
{int data;struct node *next;struct node *prev;
};//创建节点
struct node * create_node(int data)
{struct node *p = (struct node *)malloc(sizeof(struct node));if(p == NULL){printf("malloc error\n");return NULL;}p->data = data;p->next = NULL;p->prev = NULL;return p;
}//头部插入节点
void insert_head(struct node *phead,struct node *new)
{struct node *p = phead;if(p == NULL)exit(0);new->next = p->next;if(p->next != NULL)p->next->prev = new;p->next = new;new->prev = p;(phead->data)++;        //头节点存储节点数量
}//尾部插入
void insert_tail(struct node *phead,struct node *new)
{struct node *p = phead;if(p == NULL)exit(0);while(p->next != NULL){p = p->next;}p->next = new;new->prev = p;new->next = NULL;(phead->data)++;        //头节点存储节点数量
}//后项遍历链表
void next_printf_link(struct node *phead)
{if(phead == NULL)exit(0);struct node *p = phead;printf("num of struct : %d \n",p->data);while(p->next != NULL){p = p->next;printf("struct data : %d\n",p->data);}
}//前项遍历链表
void prev_printf_link(struct node *phead)
{if(phead == NULL)exit(0);struct node *p = phead;printf("num of struct : %d \n",p->data);while(p->next != NULL){p = p->next;}while(p->prev != NULL){printf("struct data : %d\n",p->data);p = p->prev;}
}//删除节点
int  delete_node(struct node *phead,int data)
{if(phead == NULL)exit(-1);struct node *p = phead;struct node *test = NULL;while(p->next != NULL){p = p->next;if(p->data == data){if(p->next == NULL){p->prev->next = NULL;   //尾节点}else{//其他节点p->prev->next = p->next;p->next->prev = p->prev;}free(p);(phead->data)--;return 0;}}printf("have no data\n");return -1;
}int main()
{//创建头节点struct node *head = create_node(0);//头部插入节点insert_head(head,create_node(1));insert_head(head,create_node(2));insert_head(head,create_node(3));insert_head(head,create_node(4));insert_head(head,create_node(5));//尾部插入节点insert_tail(head,create_node(1));insert_tail(head,create_node(2));insert_tail(head,create_node(3));insert_tail(head,create_node(4));insert_tail(head,create_node(5));//遍历节点next_printf_link(head);//删除节点delete_node(head,2);delete_node(head,5);delete_node(head,4);//next遍历节点next_printf_link(head);//prev遍历节点prev_printf_link(head);return 0;
}

结果示例:

http://www.15wanjia.com/news/171732.html

相关文章:

  • 旅游网站建设的目标是什么电商交流平台有哪些
  • 如何通过轻淘客做网站百度云主机做网站
  • wordpress acf主题选项关键词推广优化排名品牌
  • 怎么才算完成一个网站东莞网络推广公司
  • 网站推广的策略网站制作需要多少钱官网
  • WordPress多站点默认设置中小网站 架构
  • 厦门做网站多少WordPress的footer文件
  • 做色网站负责网站开发的岗位
  • 做视频素材哪个网站好网站实施要求
  • 吴桥县做网站价格网页制作工具下载
  • 营销网站是什么意思酒店用品网站源码
  • 好用的html 模板网站品牌建设不足怎么表达
  • 汕头快速建站模板wordpress 评论邮件通知
  • 微信第三方网站开发教程凡客品牌
  • 徐州网站制作哪家好wordpress 小工具使用方法
  • wordpress页面中去掉分页惠州seo关键词
  • 承德手机网站建设蛋糕店网站模板
  • 怎么看网站文章的收录工商营业执照年检
  • c苏宁网站开发购物网站项目简介
  • 企业展示建设网站盐城快速建设网站公司
  • 化妆品电子商务网站开发流程描述房地产公司的网站建设方案
  • 网站开发费用如何账务处理东莞网站制作个性化
  • 一学一做演讲视频网站西部域名网
  • wap网站 全屏wordpress type参数
  • 贵阳网站建设策划方案线上营销公司
  • 个人网站 推荐优化设计五年级上册语文答案
  • php怎样做网站管理后台网站搭建好有什么内容可以修改
  • 大庆网站设计wordpress 定期删除
  • 可以做富集分析的网站广东建设继续教育网站
  • 网站绝对地址兰州网站seo收费标准