-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemp.cpp
More file actions
56 lines (40 loc) · 772 Bytes
/
temp.cpp
File metadata and controls
56 lines (40 loc) · 772 Bytes
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
#include <iostream>
using namespace std;
struct Node
{
Node * left;
Node * right;
int value;
Node():left(0),right(0){}
~Node()
{
if (left) delete left;
if (right) delete right;
}
};
void Print (Node * x, int & id)
{
if (!x) return;
Print (x->left,id);
id++;
cout << id << ' ' << x->value << endl;
Print (x->right,id);
}
int main()
{
Node * root=new Node;
root->value=10;
root->left=new Node;
root->left->value=20;
root->left->left=new Node;
root->left->left->value=30;
root->right=new Node;
root->right->value=40;
root->right->left=new Node;
root->right->left->value=50;
int id=0;
Print(root,id);
delete root;
cin.get();
return 0;
}