-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevision.cpp
More file actions
72 lines (63 loc) · 1.29 KB
/
Copy pathrevision.cpp
File metadata and controls
72 lines (63 loc) · 1.29 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
#include <bits/stdc++.h>
#include <vector>
using namespace std;
class node
{
public:
int data ;
node* left;
node* right;
//constructor
node(int data)
{
this->data=data;
left=NULL;
right=NULL;
}
};
node* BuildTree( node* root)
{
cout<<"enter the data"<<endl;
int data;
cin>>data;
root= new node(data);
if(data==-1)
{
return NULL;
}
cout<<"enter the data for left node of "<<data<<endl;
// recursion for buiding left nodes
root->left= BuildTree(root->left);
cout<<"enter the data for right node of "<<data<<endl;
//recursive call
root->right= BuildTree(root->right);
return root;
}
void InorderTraversal( node* root)
{
if(root==NULL)
{ return;}
// left most call
InorderTraversal(root->left);
//printing the root data after returning from left
cout<<root->data<<" ";
//goint to the right tree
InorderTraversal(root->right);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
node* root=NULL;
root=BuildTree(root);
// int cnt=0;
// Number_leaf_nodes(root , cnt);
// cout<<endl;
// cout<<cnt<<endl;
InorderTraversal(root);
return 0;
}