#include<stdio.h>
#include<stdlib.h>
//定义 双链表
typedef struct DNode {
int data;
struct DNode* prior, * next;
}DNode, * DLinkList;
//初始化
bool InitDLinkList(DLinkList& L) {
L = (DNode*)malloc(sizeof(DNode)); //分配头节点
if (L == NULL)
return false;
L->prior = NULL; //头节点的prior 始终指向NULL
L->next = NULL; //如果是循环双链表此处变为L->prior=L L->next=L;
return true;
}
//判断空
bool empty(DLinkList L) {
return(L->next == NULL);
}
//插入操作 在p节点后插入s节点
bool InsertNextDNode(DNode* p, DNode* s) {
if(p==NULL||s==NULL)
return false;
s->next = p->next;
if(p->next->prior!=NULL)
p->next->prior = s;
s->prior = p;
p->next = s;
return true;
}
//删除操作 在p的后继节点q
bool DeleteNextDNode(DNode* p) {
DNode* q = p->next;
if (p == NULL || q == NULL)
return false;
p->next = q->next;
if (q->next->prior != NULL)
q->next->prior = p;
free(q);
return true;
}
//定义 静态链表
#define MaxSize 10
struct Node {
int data;
int next;
};
typedef struct {
int data;
int next;
}SLinkList[MaxSize];
08-29
1128
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-24
881
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-19
9047
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交