循环链表

单链表

初始化

1
2
3
4
5
6
7
8
9
10
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
bool InitLinkList(LinkList &L){
L=(LNode*)malloc(sizeof(LNode));
if(L==NULL)return false;
L->next=L;
return true;
}

判断是否为空

1
2
3
4
bool Empty(LinkList L){
if(L->next==L)return true;
else return false;
}

判断结点p是否为最后一个结点

1
2
3
4
bool isTail(LinkList L,LNode *p){
if(p->next==L)return true;
else return false;
}

循环双链表

初始化

1
2
3
4
5
6
7
8
9
10
11
typedef struct DLNode{
int data;
struct DLNode *prior,*next;
}DLNode,*DLinkList;
bool InitLinkList(DLinkList L){
L=(DLNode*)malloc(sizeof(DLNode));
if(L==NULL)return false;
L->next=L;
L->prior=L;
return true;
}

判断是否为空

1
2
3
4
bool Empty(DLinkList L){
if(L->next==L)return true;
else return false;
}

判断结点p是否为表尾结点

1
2
3
4
bool isTail(DLinkList L,DLNode *p){
if(p->next==L)return true;
else return false;
}

在结点p后插入结点s

1
2
3
4
5
6
7
bool InsertNextDNode(DLNode *p,DLNode *s){
s->next=p->next;
p->next->prior=s;
p->next=s;
s->prior=p;
return true
}

知识回顾与重要考点