-
Notifications
You must be signed in to change notification settings - Fork 779
/
BST
44 lines (38 loc) · 798 Bytes
/
BST
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
#include<iostream>
using namespace std;
// struct Node{
// int data;
// Node *lchild;
// Node *rchild;
// };
class node {
public:
int data;
node* left;
node* right;
node(int d) {
this -> data=d;
this -> left=NULL;
this -> 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 data for inserting in left of"<<data<<endl;
root->left=buildTree(root->left);
cout<<"Enter data for inserting in right of"<<data<<endl;
root->right=buildTree(root->right);
return root;
}
int main(){
node* root=NULL;
//creating a tree
root=buildTree(root);
return 0;
}