Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anybody help with remove function of bst? _____________________________________________________________________________________________________ bst .h class btree{ public: btree(); void insert(int index, int entry); int root(int index); int left(int

Can anybody help with remove function of bst?

_____________________________________________________________________________________________________

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();

void remove();

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<

}

void btree remove()

{

}

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

LO2 Identify components of workflow analysis.

Answered: 1 week ago