循环双链表相较于普通双链表只要记住所有的NULL改为头指针即可,本文提供循环双链表的考研写法
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
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;
L->next=NULL;
}
bool InsertNextDnode(Dnode *p,Dnode *s){
s->next=p->next;
p->next->prior=s;
p->next=s;
s->prior=p;
}
bool deleteNextDnode(Dnode *p){
Dnode *s=p->next;
p->next=s->next;
s->next->prior=p;
free(s);
}
int main(int argc, char** argv) {
Dlinklist L;
initDlinklist(L);
return 0;
}
|