forked from iiitu-force/hacktoberfest22
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinarySearchTree.cpp
More file actions
62 lines (55 loc) · 1.46 KB
/
Copy pathBinarySearchTree.cpp
File metadata and controls
62 lines (55 loc) · 1.46 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
#include<iostream>
#include "BST.h"
#include <queue>
using namespace std;
BinaryTreeNode<int> *takeInputLevelWise()
{
int rootData;
cout << "Enter Root Data" << endl;
cin >> rootData;
if (rootData == -1)
return NULL;
BinaryTreeNode<int> *root = new BinaryTreeNode<int>(rootData);
queue<BinaryTreeNode<int> *> pendingNodes;
pendingNodes.push(root);
while (pendingNodes.size() != 0)
{
BinaryTreeNode<int> *front = pendingNodes.front();
pendingNodes.pop();
cout << "Enter Left child of " << front->data << endl;
int leftChildData;
cin >> leftChildData;
if (leftChildData != -1)
{
BinaryTreeNode<int> *child = new BinaryTreeNode<int>(leftChildData);
front->left = child;
pendingNodes.push(child);
}
cout << "Enter Right child of " << front->data << endl;
int rightChildData;
cin >> rightChildData;
if (rightChildData != -1)
{
BinaryTreeNode<int> *child = new BinaryTreeNode<int>(rightChildData);
front->right = child;
pendingNodes.push(child);
}
}
return root;
}
int main()
{
BST b;
b.insert(10);
b.insert(5);
b.insert(20);
b.insert(7);
b.insert(13);
b.insert(3);
b.insert(15);
// b.printTree();
b.deleteData(10);
b.printTree();
}
// for input copy paste ->
// 1 2 3 4 5 6 7 -1 -1 -1 -1 8 9 -1 -1 -1 -1 -1 -1