{
int dat;
struct doubnode *prev;
struct doubnode *next;
}Dnode;
/*创建一个双向循环链表头节点(空表)*/
Dnode *Create_doublist_head(void)
{
Dnode *dhead = NULL;
/*1.分配空间*/
dhead = (Dnode *)malloc(sizeof(Dnode));
if(NULL == dhead)
{
perror("malloc");
return NULL;
}
/*赋值*/
dhead->dat = -1;
dhead->prev = dhead->next = dhead;
return dhead;
}
/*头插入-子函数*/
static Dnode *_Insert_doublist_head(Dnode *dhead,int data)
{
Dnode *dnew = NULL;
/*1.为新插入节点分配空间*/
dnew = (Dnode *)malloc(sizeof(Dnode));
if(NULL == dnew)
{
perror("malloc");
return NULL;
}
dnew->dat = data;// 2.赋值
/*3.插入操作*/
dnew->next = dhead->next;
dhead->next->prev = dnew;
dnew->prev = dhead;
dhead->next = dnew;
return dhead;
}
/*头插入-控制函数*/
Dnode *Insert_doublist_head(Dnode *dhead)
{
int data;
do{
printf("Please input dat for doublist head insert(-1:quit)\n");
scanf("%d",&data);
if(-1 == data)
{
break;
}
dhead = _Insert_doublist_head(dhead,data);
}while(1);
return dhead;
}
/*尾插入-子函数*/
static Dnode *_Insert_doublist_tail(Dnode *dhead,int data)
{
Dnode *dnew = NULL;
/*1.为新插入节点分配空间*/
dnew = (Dnode *)malloc(sizeof(Dnode));
if(NULL == dnew)
{
perror("malloc");
return NULL;
}
dnew->dat = data;// 2.赋值
/*尾插入操作*/
dnew->prev = dhead->prev;
dhead->prev->next = dnew;
dhead->prev = dnew;
dnew->next = dhead;
return dhead;
}
/*尾插入-控制函数*/
Dnode *Insert_doublist_tail(Dnode *dhead)
{
int data;
do{
printf("Please input dat for doublist head insert(-1:quit)\n");