DLoopLinkList.h
// // DLoopLinkList.h // 双向循环链表 2013/03 // #ifndef DLOOP_LINK_LIST_H #define DLOOP_LINK_LIST_H typedef int ElemType; typedef struct DLoopLinkList { struct DLoopLinkList *prior; ElemType data; struct DLoopLinkList *next; }DLoopLinkList, *PtrDLoopLinkList; void InitDLoopLinkList(PtrDLoopLinkList); void DestoryDLoopLinkList(PtrDLoopLinkList); void InsertDLoopLinkList(PtrDLoopLinkList, int, ElemType); void ShowDLoopLinkList(PtrDLoopLinkList); void Append(PtrDLoopLinkList, ElemType); void Delete(PtrDLoopLinkList, int, ElemType *); #endif
DLoopLinkList.c
#include <stdlib.h> #include <stddef.h> #include <stdio.h> #include "DLoopLinkList.h" void InitDLoopLinkList(PtrDLoopLinkList ptrDLL) { ptrDLL->prior = ptrDLL; ptrDLL->next = ptrDLL; } typedef PtrDLoopLinkList PDLLL; void DestoryDLoopLinkList(PtrDLoopLinkList ptrDll) { PDLLL pite; // 用于遍历的指针 PDLLL temp; // 用于存放要删除的节点的临时指针 pite = ptrDll->next; // 指向首元节点 while(pite != ptrDll) { temp = pite; pite = pite->next; free(temp); } ptrDll->prior = NULL; } // // index表示插入到index之前 // void InsertDLoopLinkList(PDLLL ptrDll, int index, ElemType data) { // 构建新节点 PDLLL newNode = NULL; PDLLL pIte = NULL; // 用来循环的指针 PDLLL pHead = ptrDll; // 头指针 int i = -1; newNode = (PDLLL)malloc(sizeof(DLoopLinkList)); newNode->data = data; pIte = pHead; // 初始化指向首元节点 // 遍历找到第i-1个节点 while(i < index - 1) { pIte = pIte->next; ++i; } //printf("i = %d, data = %d", i, pIte->data); if(i == index - 1) { //printf("call insert\n"); newNode->prior = pIte; pIte->next->prior = newNode; newNode->next = pIte->next; pIte->next = newNode; } } void ShowDLoopLinkList(PDLLL dllList) { PDLLL pIte; pIte = dllList->next; //printf("pIte = %p\n", pIte); while(pIte != dllList) { printf("%-4d",pIte->data); pIte = pIte->next; } printf("\n"); } void Append(PtrDLoopLinkList pdl, ElemType data) { // 创建一个节点 PDLLL newNode = (PDLLL)malloc(sizeof(DLoopLinkList)); newNode->data = data; newNode->next = pdl->prior->next; pdl->prior->next = newNode; newNode->prior = pdl->prior; pdl->prior = newNode; } void Delete(PtrDLoopLinkList pdl, int index, ElemType * pData) { int i = 0; PDLLL pIte = pdl->next; while(i < index && pIte != pdl) { pIte = pIte->next; ++i; } if(i == index && pIte != pdl) { *pData = pIte->data; pIte->prior->next = pIte->next; pIte->next->prior = pIte->prior; free(pIte); } }
main.c
#include <stdio.h> #include "DLoopLinkList.h" #define Insert InsertDLoopLinkList int main(int argc, char* argv[]) { DLoopLinkList dl; int i = 0; ElemType e; InitDLoopLinkList(&dl); for(; i < 100; ++i) { Append(&dl, i); } Insert(&dl, 100, 100); Insert(&dl, 0, 100); Insert(&dl, 1, 101); Delete(&dl, 0, &e); printf("The element which be deleted:%d\n", e); Delete(&dl, 101, &e); printf("The element which be deleted:%d\n", e); ShowDLoopLinkList(&dl); printf("<<ShowDLoopLinkList>> ends.\n"); DestoryDLoopLinkList(&dl); }
相关推荐
利用双向循环链表来实现对长整数的存储。每个节点只存储四位十进制数字。选择该数据结构来完成长整数的加减运算是因为要对长整数进行运算,需要对长整数进行存储,所以选择用链表对长整数存储,又由于存储的顺序是从...
双向循环链表 C++实现 双向循环链表 C++实现 双向循环链表 C++实现 双向循环链表 C++实现 双向循环链表 C++实现
Linux操作系统中通用双向循环链表的实现分析.pdf
数据结构课程设计实现双向循环链表,我这有详细的课程设计说明书以及答辩ppt,有需要的可以留言哈 ,仅供参考 嘿嘿
利用了双向循环链表实现了快速排序算法
双向循环链表,队列,代码详细实现,已进行详细备注。
双向循环链表的程序,包括循环链表的生成,链表结点的插入和删除。
单链表实现双向循环链表单向链表存在一个弊端就是,当需要获取某个结点p的前驱时,需要从头指针开始遍历链表,获得“前驱”的执行时间为O(n),为了克服单向链表的这种缺点,可以利用双向链表。在双向链表中有两个...
数据结构课程设计报告基于双向循环链表的通讯录设计
用单向链表存储航班信息,双向链表存储乘客信息,并可以订票,退票和查询的航班订票系统!
C++实现的带头结点的双向循环链表, 数据结构课设.。
一个精简的双向循环链表C语言实现,与大家共享
使用C++实现的双向循环链表,支持定点插入,定点删除,正/逆向输出等功能,欢迎审阅
本人自己编写的双向循环链表源码,分享给大家,存在什么问题请指出
C语言版双向循环链表,双向循环链表经典程序,用于指针进行编写的C语言程序。。。
用C++和Java实现带头节点的双向循环链表,要继承linearList类,并实现它的所有功能,另外,必须实现双向迭代器。 实现带头节点的双向循环链表,要具有以下的功能: 判断表是否为空,如果为空则返回true,不空返回...
利用双向循环链表作为储存结构设计并实现一个通讯录程序。可以实现信息的添加、插入、删除、查询和统计等功能 1.2 课程设计要求 (1) 每条信息至少包含:姓名(name)、街道(street)、城市(city)、邮编、(eip...
双向循环链表解决约瑟夫实验报告, 双向循环链表解决约瑟夫实验报告 双向循环链表解决约瑟夫实验报告双向循环链表解决约瑟夫实验报告
双向的循环链表的C++源代码 实现正逆序遍历,链表归并,插入,删除,查询等基本操作
c语言实现:利用双向循环链表,用户输入一个数使得26个字母的排列发生变化,例如用户输入3,输出结果:DEFGHIJKLMNOPQRSTUVWXYZABC