-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathinoreder.cpp
50 lines (41 loc) · 969 Bytes
/
inoreder.cpp
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
#include<bits/stdc++.h>
using namespace std;
class Treenode{
public:
int data;
Treenode* left;
Treenode* right;
Treenode(int data){
this->data=data;
this->left=NULL;
this->right=NULL;
}
};
//creating tree by recursion
Treenode* createTree(Treenode* root)
{
int d;
cout<<"enter data"<<endl;
cin>>d;
root=new Treenode(d);
if(d==-1) return NULL;
cout<<"enter data for left"<<endl;
root->left=createTree(root->left);
cout<<"enter data for right"<<endl;
root->right=createTree(root->right);
return root;
}
void inordertraversal(Treenode* root)
{
if(root==NULL) return;
if(root->left) inordertraversal(root->left);
cout<<root->data<<" ";
if(root->right) inordertraversal(root->right);
}
int main()
{
Treenode* root=NULL;
root=createTree(root);
cout<<"inordertraversal traversal is:"<<endl;
inordertraversal(root);
}