mirror of
https://github.com/happyflyer/wangdao-data-structure.git
synced 2026-05-01 06:01:41 +08:00
完成双链表、循环链表、静态链表
This commit is contained in:
39
ch2/circular-link/single.cpp
Normal file
39
ch2/circular-link/single.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#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)
|
||||
{
|
||||
return L->next == L;
|
||||
}
|
||||
|
||||
// 判断 p 结点是否为表尾结点
|
||||
bool isTail(LinkList L, LNode *p)
|
||||
{
|
||||
return p->next == L;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
LinkList L;
|
||||
InitList(L);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user