-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path191.cpp
More file actions
76 lines (62 loc) · 1.37 KB
/
Copy path191.cpp
File metadata and controls
76 lines (62 loc) · 1.37 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
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
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int data;
Node *left, *right;
};
Node* newNode(int data)
{
Node* node = new Node;
node->data = data;
node->left = node->right = NULL;
return node;
}
void leftTraversal(Node * root){
if(!root) return;
if(root->left) {
cout<<root->data<<" ";
leftTraversal(root->left);
}
else if(root->right){
cout<<root->data<<" ";
leftTraversal(root->right);
}
}
void bottomTraversal(Node * root){
if(!root) return;
if(!root->left && !root->right) cout<<root->data<<" ";;
bottomTraversal(root->left);
bottomTraversal(root->right);
}
void rightTraversal(Node * root){
if(!root) return;
if(root->right) {
rightTraversal(root->right);
cout<<root->data<<" ";
}
else if(root->left){
rightTraversal(root->left);
cout<<root->data<<" ";
}
}
void boundary(Node * root){
leftTraversal(root);
bottomTraversal(root);
rightTraversal(root->right);
}
int main()
{
Node* root = newNode(8);
root->left = newNode(3);
root->right = newNode(10);
root->left->left = newNode(1);
root->right->left = newNode(9);
root->left->right = newNode(6);
root->right->right = newNode(14);
root->right->right->left = newNode(13);
root->left->right->left = newNode(4);
root->left->right->right = newNode(7);
boundary(root);
return 0;
}