数据结构--双向循环链表c语言实现
来源:互联网 发布:路由器mac什么意思 编辑:程序博客网 时间:2024/03/29 23:26
XList.h如下:
#ifndef __LIST_H#define __LIST_Htypedef struct LNode{int data;struct LNode* next;struct LNode* pre;}LNode, *List;void InitList(List list);//初始化化单链表void Insert_Head(List list, int var);//头插节点void Insert_Tail(List list, int var);//尾插节点LNode *Search(List list, int key);//查找keyLNode *SearchPre(List list, int key);//查找key的前驱bool Delete(List list, int key);//删除keybool isEmpty(List list);//是否为空int Length(List list);//返回链表的数据节点个数void Show(List list);//打印void Destroy(List list);//删除list所有数据节点#endif
XList.c如下:
</pre><pre name="code" class="cpp">#include"XList.h"#include<stdio.h>#include<stdlib.h>#include<assert.h>static LNode* BuyNode(int val){LNode *p = (LNode*)malloc(sizeof(LNode));assert(p != NULL);p->data = val;p->next = NULL;p->pre = NULL;return p;}void InitList(List list)//初始化化单链表{assert(list);list->next = list;list->pre = list;}void Insert_Head(List list, int var)//头插节点{LNode *p = BuyNode(var);LNode *tmp = list;p->next = list->next;//list->next->pre = p;//多余了p->pre = list;list->next = p;while (tmp->next != list)tmp = tmp->next;list->pre = tmp;}void Insert_Tail(List list, int var)//尾插节点{LNode *last = list;LNode *p = BuyNode(var);while (last->next != list)last = last->next;last->next = p;p->pre = last;p->next = list;list->pre = p;}LNode *Search(List list, int key)//查找key{LNode* p = list->next;while (p!= list){if (p->data == key)return p;p = p->next;}return NULL;}LNode *SearchPre(List list, int key)//查找key的前驱{LNode* p = list->next;while (p!= list){if (p->data == key)return p->pre;p = p->next;}return NULL;}bool Delete(List list, int key)//删除key{LNode* p = Search(list, key);if (p == NULL)return false;p->next->pre = p->pre;p->pre->next = p->next;free(p);return true;}bool isEmpty(List list)//是否为空{if (list->next = list)return true;return false;}int Length(List list)//返回链表的数据节点个数{int count = 0;LNode* p = list;while (p->next != list){count++;p = p->next;}return count;}void Show(List list)//打印{LNode* p = list;while (p->next != list){printf("%d ", p->next->data);p = p->next;}printf("\n");}void Destroy(List list)//删除list所有数据节点{LNode* p = list->next;LNode* t = p;while (p!= list){p->next->pre = p->pre;p->pre->next = p->next;t = p;free(t);}free(list);}
0 0
- 数据结构--双向循环链表c语言实现
- 数据结构--双向循环链表C实现
- C语言实现双向循环链表
- C语言实现双向循环链表
- C语言实现双向循环链表
- C语言实现双向循环链表
- C语言双向循环链表实现
- C语言实现双向循环链表
- c语言实现双向循环链表
- c语言_数据结构_双向循环链表
- c语言_数据结构_双向循环链表
- 数据结构的C实现_双向循环链表
- C语言 实现循环链表及双向链表
- 双向循环链表的C语言实现
- 双向循环链表实现文件C语言
- C语言实现双向循环链表[下]
- linux中C语言实现双向循环链表
- C语言使用非循环双向链表实现队列
- “双十一”大战引发四大疑问(图)
- Asp.net MVC在View里动态捆绑压缩引用的js
- "双十一"战火将燃专家称商标被撤销可能性小
- Asp.net MVC在View里动态捆绑压缩引用的js
- NOIP复习篇———枚举
- 数据结构--双向循环链表c语言实现
- hdu4693 Huge String,高精度,dp
- Asp.net MVC在View里动态捆绑压缩引用的js
- 上帝模式,,即"God Mode”,或称为“完全控制面板”
- Asp.net MVC在View里动态捆绑压缩引用的js
- 尝试把vim打造成为IDE
- Asp.net MVC在View里动态捆绑压缩引用的js
- C ch11重點整理-Bit Operation
- Asp.net MVC在View里动态捆绑压缩引用的js