头插法新建链表实战
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*ListNode;
void head_insert(ListNode &L){
L = (ListNode)malloc(sizeof(LNode));
L->next=NULL;
ElemType x;
scanf("%d",&x);
LNode *s;
while (x!=9999){
s = (ListNode)malloc(sizeof(LNode));
s->data=x;
s->next = L->next;
L->next=s;
scanf("%d",&x);
}
}
void print_list(ListNode L){
L = L->next;
while (L!=NULL){
printf("%3d",L->data);
L = L->next;
}
}
int main(){
ListNode L;
head_insert(L);
print_list(L);
return 0;
}