C++ PROGRAMMING Topic: Binary Search Trees Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)
C++ PROGRAMMING Topic: Binary Search Trees Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)
Chapter3: Data Representation
Section: Chapter Questions
Problem 1VE
Related questions
Question
C++ PROGRAMMING
Topic: Binary Search Trees
Explain the c++ code below.: SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS
It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)
It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)
int childCount(node* p) {
bool Cright = false;
bool Cleft = false;
if(p->right != NULL){
Cright = true;
}
if(p->left != NULL){
Cleft = true;
}
if(Cleft == true && Cright== true){
return 2;
}
if(Cright){
return 1;
}
if(Cleft){
return -1;
}
return 0;
}
int set(node* p, int e) {
int elem = p->element;
p->element = e;
return elem;
}
node* addSibling(node* p, int e) {
node* P = p->parent;
if(P != NULL){
if(sibling(p) == NULL){
if(sibling(p) == left(P)){
return addLeft(P,e);
}
return addRight(P,e);
}
}
cout<<"Error"<<endl;
return NULL;
}
void clear(){
clear_postorder(root);
}
void attach(node* p, BTree* t1, BTree* t2) {
if(p->right == NULL && p->left == NULL){
if(t1->root != NULL){
t1->root->parent = p;
p->left = t1->root;
}
if(t2->root != NULL){
t2->root->parent = p;
p->right = t2->root;
}
return;
}
cout<<"Error"<<endl;
}
int remove(node* p) {
if(left(p) == NULL || right(p) == NULL){
node* P = NULL;
node* childNode = NULL;
if(p->parent != NULL){
P = p->parent;
}
else{
P = p;
if(left(P) != NULL){
childNode = P->left;
childNode->parent = NULL;
root = childNode;
}
else{
childNode = P->right;
childNode->parent = NULL;
root = childNode;
}
int elem = P->element;
free(P);
size--;
return elem;
}
if(left(P) == p){
if(left(p) != NULL){
P->left = childNode;
childNode = p->left;
if(p->left != NULL || p->right != NULL){
childNode->parent = P;
}
}
else{
childNode = p->right;
P->left = childNode;
if(p->left != NULL || p->right != NULL){
childNode->parent = P;
}
}
}
else{
if(left(p) != NULL){
childNode = p->left;
P->right = childNode;
if(p->left != NULL || p->right != NULL){
childNode->parent = P;
}
}
else{
childNode = p->right;
P->right = childNode;
if(p->left != NULL || p->right != NULL){
childNode->parent = P;
}
}
}
int elem = p->element;
free(p);
return elem;
size--;
}
cout<<"Error"<<endl;
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 7 steps
Recommended textbooks for you
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning