Skip to content

Commit

Permalink
Merge pull request #188 from saurabhh-svg/main
Browse files Browse the repository at this point in the history
Binary Search Tree Template
  • Loading branch information
akshatmittal61 committed Oct 24, 2022
2 parents d1ee637 + 35ac530 commit 8555858
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions BinarySearchTree.cpp
@@ -0,0 +1,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

0 comments on commit 8555858

Please sign in to comment.