链表与递归

 1 struct Node
 2 {
 3     int value;
 4     Node *next;
 5 };
 6 void readNode(Node *list)
 7 {
 8     if (list!=NULL)
 9     {
10         if (list->next!=NULL)
11         {
12             readNode(list->next);
13         }
14         printf("%d\t",list->value);
15     }
16     return;
17 }
18 void test()
19 {
20     Node *list,*p,*q;
21     list=(Node *)malloc(sizeof(Node));
22     list->value=0;
23     list->next=NULL;
24 
25     int i=0;
26     p=list;
27     for (i=1;i<3;i++)
28     {
29         q=(Node *)malloc(sizeof(Node));
30         q->value=i;
31         q->next=NULL;
32         p->next=q;
33         p=p->next;
34     }
35     readNode(list);
36     return;
37 }

posted on 2012-11-09 16:20  lianshisxq  阅读(132)  评论(0编辑  收藏  举报

导航