一、双向循环链表
二、用C语言实现双向循环链表
1、构造存储结构
typedef int datatype;
typedef struct doublelist{
datatype data;
struct doublelist *next, *prev;
}double_list, *double_plist;
2、初始化
初始化主要工作:①申请头结点内存空间;②
head->next = head; head->prev = head;
3、插入结点
(1)、向p指向的结点后面插入new指向的结点
步骤①:
new->next = p->next;
步骤②:p->next->prev = new;
步骤③:new->prev =p;
步骤④:p->next = new;
/* 向p指向的结点后面插入new指向的结点 */
void insert_doublelist_behind(double_plist p, double_plist new)
{
new->next = p->next;
p->next->prev = new;
new->prev = p;
p->next = new;
}
(2)、向p指向的结点前面插入new指向的结点
步骤①:
new->prev = p->prev;
步骤②:p->prev->next = new;
步骤③:new->next = p;
步骤④:p->prev = new;
/* 向p指向的结点前面插入new指向的结点 */
void insert_doublelist_tail(double_plist p, double_plist new)
{
new->prev = p->prev;
p->prev->next = new;
new->next = p;
p->prev