#include "stdio.h"
#include "stdlib.h"typedef int datatype_t;typedef struct node {datatype_t data;struct node *next;
} looplist_t;// 单向循环链表创建
looplist_t *looplist_create() {looplist_t *head = (looplist_t *) malloc(sizeof(looplist_t));if (head == NULL) {exit(0);}head->next = head;return head;
}//头插法
int looplist_head_insert(looplist_t *head, datatype_t value) {looplist_t *temp = (looplist_t *) malloc(sizeof(looplist_t));if (temp == NULL) {exit(0);}temp->data = value;temp->next = head->next;head->next = temp;return 0;
}//显示数据
void looplist_show(looplist_t *head) {looplist_t *p = head;while (head->next != p) {head = head->next;printf("%d ", head->data);}printf("\n");
}int main() {looplist_t *head = looplist_create();looplist_head_insert(head, 3);looplist_head_insert(head, 5);looplist_head_insert(head, 6);looplist_head_insert(head, 1);looplist_show(head);return 0;
}
运行效果