-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBST TREE.CPP
48 lines (42 loc) · 986 Bytes
/
BST TREE.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
#include <iostream>
using namespace std;
struct node {
node* right;.
node* left;
int info;
};
node* newnode(int info) {
node* newnode = new node;
newnode->info = info;
newnode->left = nullptr;
newnode->right = nullptr;
return newnode;
}
int main() {
int x;
char choose;
int y,i;
cout<<"how many values you want to enter: ";
cin>>y;
node* root = newnode(x);
for(int i=0;i<y;i++){
cout << "Choose direction (L/R): ";
cin >> choose;
switch (choose) {
case 'L':
cout << "Enter the value for the left child: ";
cin >> x;
root->left = newnode(x);
break;
case 'R':
cout << "Enter the value for the right child: ";
cin >> x;
root->right = newnode(x);
break;
default:
cout << "Invalid choice";
break;
}
}
return 0;
}