思维导图
test.c
#include"head.h"
//创建
DoulinkPtr create()
{
DoulinkPtr H = (DoulinkPtr)malloc(sizeof(Doulink));
if(NULL == H)
{
printf("创建失败!\n");
return NULL;
}
H->len = 0;
H->prior = H;
H->next = H;
}
//申请节点,封装数据
DoulinkPtr create_n(DataType e)
{
DoulinkPtr L = (DoulinkPtr)malloc(sizeof(Doulink));
if(NULL == L)
{
printf("申请失败!\n");
return NULL;
}
L->data = e;
L->prior = NULL;
L->next = NULL;
return L;
}
//判空
int empty(DoulinkPtr H)
{
if(NULL == H)
{
printf("判空失败!\n");
return -1;
}
return H->len == 0;
}
//尾插
int tail_add(DoulinkPtr H,DataType e)
{
if(NULL == H)
{
printf("插入失败!\n");
return 0;
}
DoulinkPtr p = create_n(e);
DoulinkPtr t =H;
while(t->next != H)
{
t=t->next;
}
p->next = H;
p->prior = t;
H->prior = p;
t->next = p;
H->len++;
return 1;
}
//遍历
void show(DoulinkPtr H)
{
if(NULL == H || empty(H))
{
printf("便利失败!\n");
return ;
}
DoulinkPtr p = H;
while(p->next != H)
{
p=p->next;
printf("%d\t",p->data);
}
putchar(10);
}
//尾删
void tail_del(DoulinkPtr H)
{
if(NULL == H || empty(H))
{
printf("删除失败\n");
return;
}
DoulinkPtr p = H;
while(p->next != H)
{
p=p->next;
}
p->next->prior = p->prior;
p->prior->next = p->next;
free(p);
p = NULL;
H->len--;
}
//销毁
void my_free(DoulinkPtr H)
{
if(NULL == H)
{
printf("销毁失败\n");
}
else
{
while(H->next != H)
{
tail_del(H);
}
}
free(H);
H = NULL;
printf("销毁成功\n");
}