-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreeTraversals.cc
95 lines (72 loc) · 1.51 KB
/
treeTraversals.cc
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<list>
#include<vector>
using namespace std;
struct Node{
Node* left;
Node * right;
int value;
}*head;
void inorder(Node *head);
void preorder(Node *head);
void postorder(Node *head);
void makeTree(Node *head);
int main(){
head = new Node;
head->value = 10;
head->left = new Node;
head->right = new Node;
head->left->value = 20;
head->right->value = 30;
head->left->left = new Node;
head->left->right = new Node;
head->right->left = new Node;
head->right->right = new Node;
head->left->left->value = 50;
head->left->right->value = 60;
head->right->left->value = 70;
head->right->right->value = 80;
head->left->left->left = NULL;
head->left->left->right = NULL;
head->left->right->left = NULL;
head->left->right->right = NULL;
head->right->left->left = NULL;
head->right->left->right = NULL;
head->right->right->left = NULL;
head->right->right->right = NULL;
inorder(head);
cout<<"\n";
preorder(head);
cout<<"\n";
postorder(head);
return 0;
}
void makeTree( Node *head){
}
void inorder(Node *node){
if(node->left != NULL){
inorder(node->left);
}
cout<<node->value<<"\n";
if(node->right != NULL){
inorder(node->right);
}
}
void preorder(Node *head){
cout<<head->value<<"\n";
if(head->left != NULL){
preorder(head->left);
}
if(head->right != NULL){
preorder(head->right);
}
}
void postorder(Node *head){
if(head->left != NULL){
postorder(head->left);
}
if(head->right != NULL){
postorder(head->right);
}
cout<<head->value<<"\n";
}