#include <stdio.h> //List结构样式 typedef struct node { int data; struct node *next; }Node; //创建head的空链 Node *createList() { Node *head = (Node *)malloc(sizeof(Node)); if(NULL == head) exit(-1); head->next = NULL; return head; } Node *insertList(Node *head,int i) //头插法插入链表数据 { Node *cur = (Node *)malloc(sizeof(Node)); cur->data = i; cur->next = head->next; head->next = cur; return head; } void traverseList(Node *head) //将链表节点中的数据输出 { head = head->next; while(head) { printf("%d\n",head->data); head = head->next; } } int main(void) { Node *head = createList(); //创建带头节点的空链表 for(int i =1; i<=10; i++) insertList(head,i); traverseList(head); return 0; }