typedef struct DLnode{
int data;
struct DLnode *next;
struct DLnode *prior;//前驱指针
}DLnode,*DLinklsit;
//初始化链表
int InitDLilnlist(DLinklsit &L)
{
L = new DLnode;
if(L ==NULL)
{
return 0;//内存不足,分配失败
}
L->next = nullptr;
L->prior = nullptr;
return 1;
}
//判断链表是否为空
bool IsEmptyDLinklist(DLinklsit &L)
{
if(L->next == nullptr)
{
cout<<"链表为空"<<endl;
return true;
}
else
{
return false;
}
}
//在p结点之后插入s结点
int InsertNextDLnode(DLnode *p,DLnode *s)
{
if(p == NULL || s == NULL)
{
return 0;
}
s->next = p->next;
if(p->next !=NULL)
{
p->next->prior = s;
}
s->prior = p;
p->next = s;
return 1;
}
//删除p结点后的q结点
int DeleteNextDLnode(DLnode *p)
{
if(p == NULL)
{
cout<<"无后继结点"<<endl;
return 0;
}
DLnode *q = p->next;//找到p的后继结点
if(q == NULL)
{
cout<<"无后继结点"<<endl;
return 0;
}
q->next = p->next;
q->next->prior = p;
delete q;
return 1;
}