-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostOrderTraversal.cpp
More file actions
48 lines (45 loc) · 1.02 KB
/
PostOrderTraversal.cpp
File metadata and controls
48 lines (45 loc) · 1.02 KB
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
#include<bits/stdc++.h>
using namespace std;
struct Node {
char data;
Node*left;
Node*right;
};
Node* root = NULL;
struct Node* insert(struct Node* root, char x) {
struct Node* temp = (struct Node*)malloc(sizeof(struct Node*));
temp->data = x;
temp->left = NULL;
temp->right = NULL;
if(root == NULL) {
root = temp;
}
else if(x <= root->data) {
root->left = insert(root->left, x);
} else {
root->right = insert(root->right, x);
}
return root;
}
void PostOrder (Node* root) {
if (root == NULL) {
return;
}
PostOrder(root->left);
PostOrder(root->right);
cout<<root->data<<" ";
}
int main() {
root = insert(root,'F');
root = insert(root,'D');
root = insert(root,'J');
root = insert(root,'B');
root = insert(root,'E');
root = insert(root,'A');
root = insert(root,'C');
root = insert(root,'G');
root = insert(root,'K');
root = insert(root,'I');
root = insert(root,'H');
PostOrder(root);
}