带表头节点的循环双向链表(头插,尾插,中间插,清除,前向显示,后向显示)
来源:互联网 发布:淘宝申请退货时间限制 编辑:程序博客网 时间:2024/06/05 08:19
#include<stdio.h>#include<stdlib.h>struct dblnode{int num;struct dblnode *prior,*next;};typedef struct dblnode Dblnode;typedef struct dblnode* Dbllink;int is_malloc_ok(Dbllink *newnode){if((*newnode) == NULL){printf("malloc error!\n");exit(-1);}return 0;}int create_newnode(Dbllink *newnode){*newnode = (Dbllink)malloc(sizeof(Dblnode));is_malloc_ok(newnode);return 0;}int create_dbllink(Dbllink *head){create_newnode(head);(*head)->prior = (*head)->next = *head;return 0;}int insert_node_head(Dbllink *head,Dbllink *newnode){(*newnode)->next = (*head)->next;(*newnode)->prior = *head;(*head)->next->prior = *newnode;(*head)->next = *newnode;return 0;}int insert_node_tail(Dbllink *head,Dbllink *newnode){(*newnode)->prior = (*head)->prior;(*newnode)->next = *head;(*head)->prior->next = *newnode;(*head)->prior = *newnode;return 0;}int insert_node_mid(Dbllink *head,Dbllink *newnode,int num){Dbllink tmp = (*head)->next;if(tmp == *head){printf("no such node!\n");return 0;}while(tmp->num != num && tmp != *head){tmp = tmp->next;}if(tmp->num == num){(*newnode)->prior = tmp;(*newnode)->next = tmp->next;tmp->next->prior = *newnode;tmp->next = *newnode;}else{printf("no such node!\n");}}int revers(Dbllink *head){Dbllink tmp = (*head)->next;while(tmp != *head){tmp->prior->next = tmp->next;tmp->next->prior = tmp->prior;free(tmp);tmp = tmp->next;}printf("revers success!\n");return 0;}int display_forword_link(Dbllink *head){Dbllink tmp = (*head)->prior;if(tmp == *head){printf("only have head_node");return 0;}while(tmp != *head){printf("num = %d\n",tmp->num);tmp = tmp->prior;}return 0;}int display_afterword_link(Dbllink *head){Dbllink tmp = (*head)->next;if(tmp == *head){printf("only have head_node!\n");return 0;}while(tmp != *head){printf("num = %d\n",tmp->num);tmp = tmp->next;}return 0;}int main(){Dbllink head = NULL;Dbllink newnode = NULL;int i;int num;create_dbllink(&head);for(i=0;i<10;i++){create_newnode(&newnode);newnode->num = i;insert_node_head(&head,&newnode);//insert_node_tail(&head,&newnode);}printf("Enter a number!\n");scanf("%d",&num);create_newnode(&newnode);newnode->num = num;insert_node_mid(&head,&newnode,newnode->num);display_forword_link(&head);revers(&head);display_afterword_link(&head); return 0;}
0 0
- 带表头节点的循环双向链表(头插,尾插,中间插,清除,前向显示,后向显示)
- 双向循环链表的头插、中插、尾插、删除、逆序顺序显示(C++实现)
- 单向循环链表的头插,尾插,中间插以及删除节点
- 带头结点的链表头插,尾插,中间插以及删除节点
- 链表的插入(头插,尾插,中间插)
- 单链表的头插、中插、尾插、删除、逆序、显示(C语言实现)
- 双向循环链表的头插尾插中间插基本操作
- 2016年12月23日学习总结----双向循环链表操作程序(头插、尾插、中间插入、删除)
- 链表模板(带表头头插)
- 单向循环链表,头插,尾插,中间插入,删除等功能
- c++链表的初始化,头插,尾插,遍历
- 2016年12月21日学习总结----单向循环链表操作程序(头插,尾插,中间插入,删除,逆序)
- 数据结构 单链表实现前插、后插、前删、后删、显示、查找等等
- 链表的创建(头插,尾插),插入,删除
- 数组的链表实现:创建(头插/尾插)、打印、删除、插入
- [数据结构]双向链表的前插操作
- 双向链表(前插操作,删除操作)
- 双向链表图解(前插操作,删除操作)
- 文章标题
- python学习笔记 序列化
- 流程控制
- VM12虚拟机安装MAC系统,解决常见错误
- 九大排序算法
- 带表头节点的循环双向链表(头插,尾插,中间插,清除,前向显示,后向显示)
- Python之put接口
- 我学习Java前期的一些小总结
- Effective C++学习笔记(三)
- 地理空间数据格式——OGC-KML
- 模板--------LCA
- Microsoft Visual Studio 工程属性表props/vsprops创建与使用
- Microsoft Visual Studio 文件识别及其用途简述
- 【codevs 1022】覆盖(匈牙利算法)