双向循环链表=普通单向链表+双指针域+循环功能;
double_loop_link.h
#ifndef _DOUBLE_LOOP_LINK
#define _DOUBLE_LOOP_LINK
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DLOOP_ERR (-1)
#define DLOOP_SUCCESS 0
#define DATA_TYPE_IS_CHAR
#if defined DATA_TYPE_IS_CHAR
typedef char DataType;
#elif defined DATA_TYPE_IS_INT
typedef int DataType;
#elif defined DATA_TYPE_IS_FLOAT
typedef float DataType;
#endif
typedef struct double_loop_link_node{
DataType data;
struct double_loop_link_node *prev;
struct double_loop_link_node *next;
}*PDLoopNode, DLoopNode;
typedef struct double_loop_link{
int length;
PDLoopNode head;
}*PDLoopLink, DLoopLink;
/* 创建一个空的双向循环链表 */
PDLoopLink CreateDLoopLink();
/* 向一个双循环链表插入数据结点 */
int InsertIntoDLoopLink(PDLoopLink head, const DataType data, const int index);
/* 从一个双向循环链表删除一个元素 */
int DeleteFromDLoopLink(PDLoopLink head, const int index);
/* 查找一个元素在双循环链表中首次出现的位置 */
int SearchInDLoopLink(PDLoopLink head, const DataType data);
/* 返回双循环链表中第index个元素 */
DataType GetElementByIndex(PDLoopLink head, const int index);
/* 获取双循环链表的长度 */
int GetDLoopLinkLength(PDLoopLink head);
/* 判断一个双循环链表是否为空 */
int DLoopLinkIsEmpty(PDLoopLink head);
/* 遍历一个双向循环链表中的元素 */
void DisplayDLoopLink(PDLoopLink head);
/* 销毁一个双向循环链表 */
void DestroyDLoopLink(PDLoopLink head);
#endif
double_loop_link.c
#include "double_loop_link.h"
PDLoopLink CreateDLoopLink()
{
PDLoopLink head = (PDLoopLink)malloc(sizeof(DLoopLink));