#include <stdio.h>
typedef struct Dnode{
ElemType data;
struct Dnode *piror,*next;
}*DLinklist,Dnode;
//双链表的初始化
bool InitDLinklist(DLinklist &L){
L=(Dnode*)malloc(sizeof(Dnode));
if(L==NULL)
return false;
L->piror=NULL;
L->next=NULL;
return true;
}
//双链表判断是不是空表
bool Empty(DLinklist &L){
if(L->piror==NULL)
return true;
}
//双链表在p节点后插入s节点
bool InsertNextDnode(Dnode *p,Dnode *s){
s->next=p->next;
if(p->next!=NULL){
p->next->piror=s;
s->piror=p;
p->next=s;
return true;
}}
//双链表的删除删除p节点的后一节点
bool DeleteNextDnode(Dnode *p){
if(p==NULL)
return false;
Dnode *q=p->next;
p->next=q->next;
if(q->next!=NULL){
q->next->piror=p;
}
free(q);
return true;
}
//释放双链表L
bool DestoryList(Dnode &L){
DeleteNextDnode(L);
free(L);
L=NULL;
}
int main(void) {
DLinklist L;
Empty(L);
//双链表的遍历
while(p!=NULL){
p=p->next;
}
return 0;
}
双链表的基础代码
最新推荐文章于 2025-12-12 16:37:00 发布
434

被折叠的 条评论
为什么被折叠?



