关于c语言链表的问题
程序代码: 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<malloc.h>
4
5 typedef struct students{
6 int a;
7 struct students *n;
8 }stu;
9
10 typedef struct list{
11 stu *ll;
12 }List;
13
14 stu *add(stu *head,int number);
15
16 int main()
17 {
18 stu *head;
19 //head=NULL;
20 List *ls;
21 ls->ll=NULL;
22 int number=1;
23 while(number!=0)
24 {
25 scanf("%d",&number);
26 head=add(ls,number);
27 }
28 while(head->n)
29 {
30 printf("------------\n%d\n",head->a);
31 head=head->n;
32 }
33 return 0;
34 }
35
36
37 int add(List *ls,int number)
38 {
39 stu *q,*l;
40 q=(stu*)malloc(sizeof(stu));
41 q->a=number;
42 q->n=NULL;
43 l=ls->ll;
44 if(l)
45 {
46 while(l->n)
47 {
48 l=l->n;
49 }
50 l->n=q;
51 }else{
52 ls->ll=q;
53 }
54 }



