Question: Programming:completeBinary search tree coding for search()and find function. use the codes binary_tree.cpp and binary_tree.h codes below. binary_tree.cpp #include using namespace std; #include binary_tree.h int main()

Programming:completeBinary search tree coding for search()and find function. use the codes binary_tree.cpp and binary_tree.h codes below.

binary_tree.cpp

#include

using namespace std;

#include "binary_tree.h"

int main()

{

BST mytree;

mytree.insertion(30);

mytree.insertion(15);

mytree.insertion(45);

mytree.display();

mytree.search(40);

mytree.search(45);

return 0;

}

Binary_tree.h code

struct nodeType

{

int info;

nodeType *left;

nodeType *right;

};

nodeType *root;

class BST

{

private:

nodeType* insertion(int x, nodeType* p);

void inorder(nodeType* t);

//nodeType* find(nodeType* t, int x);

public:

void insertion(int x);

void display();

//void search(int x);

};

void BST::inorder(nodeType* t)

{

if(t == NULL)

{

cout<<"The tree is empty"<

return;

}

inorder(t->left);

cout<info<

inorder(t->right);

}

void BST::display()

{

inorder(root);

cout<

}

nodeType* BST::insertion(int x, nodeType* p)

{

if( p == NULL)

{

// create a new node

p = new nodeType;

p->info = x;

p->left = NULL;

p->right = NULL;

}

else if(x < p->info)

p->left = insertion(x, p->left);

else if(x > p->info)

p->right = insertion(x, p->right);

return p;

}

void BST::insertion(int x)

{

root = insertion(x, root);

}

                        

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!