循环链表与单链表基本一样,就是最后的尾指针指向头就可以
//节点类型
typedef struct circular_list_node
{
int data;
struct circular_list_node *next;
} LinkList;
//初始化循环链表为空
LinkList *InitCircularList(LinkList *CList)
{
CList = (LinkList *)malloc(sizeof(LinkList));
if (!CList)
{
exit(-1);
}
memset(CList, 0, sizeof(LinkList));
CList->next = CList;
return CList;
}
//尾插法插建立循环链表
LinkList *TailInsertNodeToList(int count)
{
LinkList *p;
LinkList *r;
LinkList *CList;
int i;
int data;
CList = InitCircularList(CList); //初始化循环链表
r = CList; //标记头指针
for (i = 0; i < count; i++)
{
scanf("%d", &data);
p = (LinkList *)malloc(sizeof(LinkList));
if (!p)
{
exit(-1