循环单链表,有些其他函数可以看我的单链表实现去修改,双链表一样
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//.是直接使用结构体名的时候才可以使用
//->是使用*结构体名(也就是给这个结构体赋予了节点的能力)的时候才可以使用
//&要对表进行更改,&必须要到位,之前出现没有&也能使用的情况纯属bug
// 单链表
//定义
typedef int Elemtype;
typedef struct LNode{
Elemtype data;
struct LNode *next;
}LNode,*LinkList;
//初始化循环单链表
bool InitList(LinkList &L){
L = (LNode*)malloc(sizeof(LNode));
if (L==NULL)
return false;
L->next=NULL;
return true;
}
//判定是否为空链表
bool Empty(LinkList L){
if(L->next==NULL)
return true;
else
return false;
}
//判定节点是否为尾节点
bool IsTail(LinkList L,LNode *p){
if(p->next==L)
return true;
else
return false;
}
循环双链表:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//.是直接使用结构体名的时候才可以使用
//->是使用*结构体名(也就是给这个结构体赋予了节点的能力)的时候才可以使用
//&要对表进行更改,&必须要到位,之前出现没有&也能使用的情况纯属bug
// 单链表
//定义
typedef int Elemtype;
//实现循环双链表
typedef struct DNode{
Elemtype data;
struct DNode *prior,*next;
}DNode,*DLinkList;
//初始化循环单链表
bool InitDLinkList(DLinkList &L){
L=(DNode*)malloc(sizeof(DNode));
if(L==NULL)
return false;
L->next=NULL;
L->prior=NULL;
return true;
}
//判定是否为空
bool Empty(DLinkList L){
if(L->next==NULL)
return true;
else
return false;
}
//判定节点是否为尾节点
bool IsTailDLinkList(DLinkList L,DNode*p){
if (p->next==L)
return true;
else
return false;
}
//在p节点后插入s节点
bool InserNextDNode(DNode *p,DNode*s){
if(p==NULL||s==NULL)
return false;
p->next->prior=s;
s->next=p->next;
p->next=s;
s->prior=p;
return true;
}