-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path2-3-3.cpp
58 lines (54 loc) · 927 Bytes
/
2-3-3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
typedef struct LNode{
int data;
struct LNode* next;
}LNode, *LinkList;
void fun(LinkList L){
if(L==NULL){
return;
}else{
fun(L->next);
cout<<L->data<<" ";
}
}
int main(){
////////////////////////////////////////////////////////////
////////////////////建立链表////////////////////////////////
LinkList L,s;
int x=0;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
cin>>x;
while(x!=9999){
s=(LinkList)malloc(sizeof(LNode));
s->data=x;
s->next=L->next;
L->next=s;
cin>>x;
}
//带头结点:
s=L->next;
//不带头结点:
//L=L->next;
//s=L;
////////////////////////////////////////////////////////////
//函数调用:返回链表
//cin>>x;
fun(L->next);
s=L->next;
//打印链表:
//while(s){
// cout<<s->data<<" ";
// s=s->next;
//}
cout<<endl;
free(s);
LinkList q;
while(L){
q=L;
L=L->next;
free(q);
}
return 0;
}