新建链表(头插法)
#include <cstdlib>
#include <cstdio>
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void List_head_Insert(LinkList& L){
L=(LinkList)malloc(sizeof (LNode));
L->next=NULL;
ElemType x;
scanf("%d",&x);
LNode *S;
while(x!=9999){
S=(LinkList)malloc(sizeof (LNode));
S->data=x;
S->next=L->next;
L->next=S;
scanf("%d",&x);
}
}
void print_list(LinkList L){
L=L->next;
while (L!=NULL){
printf("%3d",L->data);
L=L->next;
}
}
int main(){
LinkList L;
List_head_Insert(L);
print_list(L);
return 0;
}