1 #include <iostream>
2 #include <stdlib.h>
3 using namespace std;
4
5 typedef struct list
6 {
7 int data;
8 struct list *next;
9 }list;
10
11 void init_list(list *&node)
12 {
13 node=NULL;
14 }
15 void insert_list(list *&node,int value)
16 {
17 if(node==NULL)
18 {
19 // cout<<"NULL"<<endl;
20 node=new list;
21 node->data=value;
22 node->next=NULL;
23 }else
24 {
25 // cout<<"NOT NULL"<<endl;
26 list *ptr=node;
27 list *p=ptr;
28 while(ptr->next !=NULL)
29 {
30 // cout<<ptr->data<<" ";
31 ptr=ptr->next;
32 }
33 list *tmp=new list;
34 tmp->data=value;
35 tmp->next=NULL;
36 ptr->next=tmp;
37 // while(p !=NULL)
38 // {
39 // cout<<p->data<<" ";
40 // p=p->next;
41 // }
42 // cout<<endl;
43 }
44 }
45 void show(list *node)
46 {
47 list *cur=node;
48 while(cur !=NULL)
49 {
50 cout<<cur->data<<" ";
51 cur=cur->next;
52 }
53 cout<<endl;
54 }
55 //反转输出
56 void rever_list(list *node)
57 {
58 if(node !=NULL)
59 {
60 rever_list(node->next);
61 cout<<node->data<<" ";
62 }
63 }
64 int main()
65 {
66 list *node=NULL;
67 // init_list(node);
68 int value=0;
69 while(cin>>value,value !=-1)
70 insert_list(node,value);
71 cout<<"show_list:";
72 show(node);
73 cout<<"rever_list:";
74 rever_list(node);
75 cout<<endl;
76 }