#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct node)
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
linklist *hcirl_creat()//带头结点的单循环链表的建立函数
{
int x;
linklist *head,*p,*rear;//尾插法建立循环链表,函数返回表尾指针
head=(struct node*)malloc(LEN);//建立循环链表的头结点
head->data=-999;
rear=head;//尾指针初值为head
printf("\n\t请随机输入正整数以0作为结束符:\n\t");
scanf("%d,&x");//读入第一个节点的值
while (x!=0)//输入数据以0位结束符
{
p=(struct node*)malloc(LEN);//生成新结点
p->data=x;//给新结点的数据域输入数据
rear->next=p;//将新结点插入到表位
rear=p;//表尾指针rear只想新的表尾
scanf("%d,&x");//输入下一个节点的数据
}
rear->next=head;//将表尾节点的指针域指向链表头结点
return(rear);//返回循环链表的表尾指针rear
}
int main()
{
linklist *hcirl_creat();
return 0;
}