头插法建立单链表 #define NULL 0 #include<stdio.h>typedef struct LNode {int data;struct LNode *next; }LNode,*LinkList;//单链表尾插法 LinkList List_TailInsert(LinkList &L){int x;L = (LinkList)malloc(sizeof(LNode)); //初始化空表LNode *r = L; //r为表尾指针scanf("&d",&x);while (x!=9999) //输入9999表示结束{LNode *s = (LNode*)malloc(sizeof(LNode));s->data = x;r->next = s;r = s;scanf("%d",&x);}r->next = NULL; //r尾结点指针置空return L; } 尾插法建立单链表 //单链表头插法 LinkList List_TailInsert(LinkList &L){int x;L = (LinkList)malloc(sizeof(LNode)); //初始化空表L->next = NULL; //必须置空!不然一直会指向未知区域!!!scanf("&d",&x);while (x!=9999) //输入9999表示结束{LNode *s = (LNode*)malloc(sizeof(LNode));s->data = x;s->next = L->next;L->next = s; //插入成功scanf("%d",&x);}return L; }