-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTREES NODES.cpp
55 lines (49 loc) · 1.09 KB
/
TREES NODES.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
51
52
53
54
55
#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;
}
void show(node* root){
if(root != nullptr){
show(root->left);
cout<<root->info;
show(root->right);}
}
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;
}
}
show(root);
return 0;
}