typedef struct node { DataType data;//数据域 struct node *next; //指针域 }looplist;
- //创建一个单向循环链表
- looplist * LooplistCreate()
- {
- looplist *head = (looplist *)malloc(sizeof(looplist));
- head->next = head;
- return head;
- }
- //插入数据
- void LooplistInsert(looplist *head,DataType value)
- {
- looplist *p = (looplist *)malloc(sizeof(looplist));
- p->data = value;
- p->next = NULL;
-
- p->next = head->next;
- head->next = p;
- }
- //遍历循环单链表
- void LooplistPrint(looplist *head)
- {
- looplist *p = head;
- while(p->next != head)
- {
- p = p->next;
- printf("%d ", p->data);
- }
- putchar('\n');
- }
//删除头结点 looplist * LooplistDeleteHead(looplist * head) { looplist *p = head; while(p->next != head) { p = p->next; } p->next = head->next; free(head); return p->next; }