Question: please implement the remove function here is a given code of bst.h and bst.cpp _____________________________________________________________________________________________________ bst .h class btree{ public: btree(); void insert(int index, int

please implement the remove function

here is a given code of bst.h and bst.cpp

_____________________________________________________________________________________________________

bst.h

class btree{

public:

btree();

void insert(int index, int entry);

int root(int index);

int left(int index);

int right(int index);

int size();

void display();

private:

int data[100];

int used;

};

_____________________________________________________________________________________________________

bst.cpp

#include

#include "bst1.h"

#include

using namespace std;

btree::btree() {

used=0;

for(int i=0;i<100;i++){

data[i]=0;

}

}

void btree::insert(int index, int entry) {

if(data[index]==0){

data[index]=entry;

used++;

}

else if(data[index]>entry){

insert(2*index+1, entry);

}

else if(data[index]

insert(2*index+2, entry);

}

}

int btree::root(int index) {

return data[index];

}

int btree::left(int index) {

return data[2*index+1];

}

int btree::right(int index) {

return data[2*index+2];

}

int btree::size() {

return used;

}

void btree::display(){

int row=ceil(log2(size()+1));

int space=1;

int index1=0;

for(int i=0;i

for(int j=0; j<20-pow(2.0,i);j++){

cout<<" ";

}

for(int k=0; k

{

cout<

index1++;

}

cout<

}

}

void pre(btree b1, int index){

//if(b1.left(index)==0 && b1.right(index)==0){

//cout<

//}

cout<

if(b1.left(index)!=0)

pre(b1, 2*index+1); // 1

if(b1.right(index)!=0)

pre(b1, 2*index+2); // 2

}

void in(btree b1, int index){

//if(b1.left(index)==0 && b1.right(index)==0){

//cout<

//}

if(b1.left(index)!=0)

in(b1, 2*index+1); // 1

cout<

if(b1.right(index)!=0)

in(b1, 2*index+2); // 2

}

void post(btree b1, int index){

//if(b1.left(index)==0 && b1.right(index)==0){

//cout<

//}

if(b1.left(index)!=0)

post(b1, 2*index+1); // 1

if(b1.right(index)!=0)

post(b1, 2*index+2); // 2

cout<

}

int main(){

btree b1;

b1.insert(0, 25);

b1.insert(0, 15);

b1.insert(0, 50);

b1.insert(0, 10);

b1.insert(0, 20);

b1.insert(0, 30);

b1.insert(0, 60);

b1.display();

cout<<"pre order traversal: ";

pre(b1, 0);

cout<

cout<<"in order traversal: ";

in(b1, 0);

cout<

cout<<"post order traversal: ";

post(b1, 0);

}

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 Databases Questions!