1.循环单链表
#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
bool InitList(LinkList &L){
L=(LNode*)malloc(sizeof(LNode));
if(L==NULL){ //内存空间不足
return false;
}
L->next=L;
return true;
}
bool Empty(LinkList &L){
if(L->next==L){
return true;
}else{
return false;
}
}
bool IsTail(LinkList L,LNode *p){
if(p->next==L){
return true;
}else{
return false;
}
}
2.循环双链表
#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=L;
L->next=L;
return true;
}
bool Empty(DLinkList L){
if(L->next==L){
return true;
}else{
return false;
}
}