Task For this assignment you are to modify your C++ BST class and add the follow
ID: 3786914 • Letter: T
Question
Task
For this assignment you are to modify your C++ BST class and add the following functionality
- Remove
- Tree Height
- FindMin
- FindMax
Your program will take in a command file called “cmd.txt” which will instruct your program on what operations to run
File Format
<command> <0 or 1 arguments>
Commands
- 1 insert
- 2 in order
- 3 post order
- 4 pre order
- 5 search
- 6 delete
- 7 findHeight
- 8 findMin
- 9 findMax
Example File
1 20
7
1 30
7
1 10
7
1 25
7
1 29
7
1 23
7
1 56
7
1 89
7
1 4
7
1 33
7
2
3
4
6 20
2
3
4
6 89
2
3
4
8
9
Expectations
You should not use any already implemented code such as a library for your linked list
Your code should be well formatted with proper spacing and proper naming
Your code should have well named variables. No a’s b’s or c’s as names unless it is for something like a loop counter
Your code must have the same output formatting you see below
I norder 4 10 20 23 25 29 30 33 56 89 Post order: 4 10 23 29 25 33 89 56 30 20 Preorder 20 10 4 30 25 23 29 56 33 89 We did not find: 5 We found: 56 We found: 10 We did not find: 99Explanation / Answer
Source Code for
BST class and add the following functionality (Remove,Tree Height,FindMin,FindMax)
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
class binarysearch
{
B data;
node1<B>*left;
node2<B>*right;
node3<B>*parent;
public:
node(B value);
`node() {};
B getdata();
void updateleft(node1<B>*pointer);
void updateright(node2<B>*pointer);
void updateparent(node3<B>*pointer);
node1<B>*left();
node2<B>*right();
node3<B>*parent();
};
node<B>:: node(B value): parent(NULL),
{
data=value;
}
B node<B> :: getdata()
{
return data;
}
void node1<B> :: updateleft(node1<B>*pointer)
{
left=pointer;
}
void node2<B> :: updateright(node2<B>*pointer)
{
right=pointer;
}
void node3<B> :: updateparent(node3<B>*pointer)
{
parent=pointer;
}
node1<B>*node<B>:: getleft()
{
return left;
}
node2<B>*node<B>:: getright()
{
return right;
}
node3<B>*node<B>:: getparent()
{
return patent;
}
class Binary
{
node<B>*root;
void removenode(node<B>*delnode);
public:
Binary():root(Null){}
`Binary();
node<B>*getroot();
node<B>*Findmin(node<B>*current);
node<B>*Findmax(node<B>*current);
node<B>*Findnode(T key);
node<B>*getsuccessor(node<B>*current);
node<B>*getpredecessor(node<B>*current);
bool addnode(node<B>*newnode);
void inorderprint(node<B>*current);
};
void binary<B>:: removenode(node<B>*delnode)
{
if(delnode)
{
removenode(delnode-->getleft());
removenode(delnode-->getright());
delete ;
}
}
void Binary<B> :: levelOrderPrint(node<B> *current)
{
int height = getHeight(current);
for(int level = 0; level < height; level++)
{
printLevel(current, level);
std::count << std::endl;
}
}
node<B>* Binary<B> :: findMin(node<B> *current)
{
node<B> *temp = current;
node<B> *prev;
while(temp)
{
prev = temp;
temp = temp->getleft();
}
return prev;
}
node<B>* Binary<T> :: findMax(node<B> *current)
{
node<B> *temp = root;
node<B> *prev;
while(temp)
{
prev = temp;
temp = temp->getRight();
}
return prev;
}
}
output::
inorder: 4 10 20 23 25 29 30 33 56 89
postorder: 4 10 23 29 25 33 89 56 30 20
preorder: 20 10 4 30 25 23 29 56 33 89
we did not find: 5
we found: 56
we found:10
we did not find: 99
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.