-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_tree_inorder.cpp
More file actions
55 lines (49 loc) · 935 Bytes
/
binary_tree_inorder.cpp
File metadata and controls
55 lines (49 loc) · 935 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
#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
int val;
Node *left;
Node *right;
Node(int val)
{
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
void inorder(Node *root)
{
if (root == NULL)
return;
inorder(root->left);
cout << root->val << " ";
inorder(root->right);
}
int main()
{
Node *root = new Node(10);
Node *a = new Node(20);
Node *b = new Node(30);
Node *c = new Node(40);
Node *d = new Node(50);
Node *e = new Node(60);
Node *f = new Node(70);
Node *g = new Node(80);
Node *h = new Node(90);
Node *i = new Node(100);
// Connections
root->left = a;
root->right = b;
a->left = c;
a->right = h;
c->right = e;
b->right = d;
d->left = f;
d->right = g;
h->right = i;
// Print using Post-Order Traversal
inorder(root);
return 0;
}