/*
* 循环链表的创建及操作
* 2018.10.23
* @L.F
*
* */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef int DataType;//定义数据类型
typedef struct Node //定义结点结构体
{
DataType Data;
struct Node *Next;
}LoopList;
LoopList *LoopListCreate()//创建一个空的循环列表
{
LoopList *h = (LoopList *)malloc(sizeof(LoopList));
h->Next = h;
return h;
}
void LoopListInsert(LoopList *h , DataType Value)//插入数据
{
LoopList *Temp = (LoopList *)malloc(sizeof(LoopList));
Temp->Data = Value;
Temp->Next = h->Next;
h->Next = Temp;
return ;
}
LoopList *LoopListCoutHead(LoopList *h)//去头结点
{
LoopList *p = h;
while(h->Next != p)
{
h = h->Next;
}
h->Next = p->Next;
free(p);
p = NULL;
return h->Next;
}
void LoopListShoeDel(LoopList *h)//删除数据
{
LoopList *p = h;
while(h->Next != p)
{
printf("%d", h->Data);
h = h->Next;
}
printf("%d\n", h->Data);
return ;
}
void LoopListShow(LoopList *h)//打印数据
{
LoopList *p = h;
while(h->Next != p)
{
h=h->Next;
printf("%d", h->Data);
}
putchar(10);
return ;
}
int main(int argc, const char *argv[])
{
int s,a,i;
LoopList *h = LoopListCreate();
while(1)
{
printf("请输入您要插入的数据总是:");
scanf("%d", &s);
for(i =0 ; i<s;i++)
{
printf("请输入您要插入的数据:");
scanf("%d", &a);
LoopListInsert(h,a);
}
LoopListShow(h);
LoopList *Pnext;
Pnext = LoopListCoutHead(h);
LoopListShoeDel(Pnext);
}
return 0;
}