++ 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) #include "node.h" #include
++ 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) #include "node.h" #include
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
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)
#include "node.h"
#include <iostream>
using namespace std;
class BTree {
node* root;
int size;
node* create_node(int num, node* parent) {
node* n = (node*) malloc( sizeof(node) );
n->element = num;
n->parent = parent;
n->right = NULL;
n->left = NULL;
return n;
}
public:
BTree() {
root = NULL;
size = 0;
}
node* left(node* p) {
return p->left;
}
node* right(node* p) {
return p->right;
}
node* sibling(node* p){
if(p != root){
node* P = p->parent;
if(P->left != NULL && P->right != NULL){
if(P->left->element == p->element){
return P->right;
}
if(P->right->element == p->element){
return P->left;
}
}
}
return NULL;
}
node* addRoot(int e) {
if(size != 0){
cout<<"Error"<<endl;
return NULL;
}
root = create_node(e,NULL);
size++;
return root;
}
node* addLeft(node* p, int e) {
if(p->left == NULL){
node* newLeft = create_node(e,NULL);
newLeft->parent = p;
p->left = newLeft;
size++;
return p->left;
}
cout << "Error" << endl;
return NULL;
}
node* addRight(node* p, int e) {
if(p->right == NULL){
node* newRight = create_node(e,NULL);
newRight->parent = p;
p->right = newRight;
size++;
return p->right;
}
cout << "Error" << endl;
return NULL;
}
int _size() {
return size;
}
bool isEmpty() {
return (size==0);
}
int childCount(node* p) {
return 0;
}
int set(node* p, int e) {
return 0;
}
node* addSibling(node* p, int e) {
return NULL;
}
void clear(){
}
void attach(node* p, BTree* t1, BTree* t2) {
}
int remove(node* p) {
return 0;
}
// WARNING. Do not modify this method.
// Doing so will nullify your score for this activity.
void print() {
if (isEmpty()) {
cout << "EMPTY";
return;
}
print_inorder(root);
cout << endl << "STATUS: " << check_health(root, NULL);
}
// WARNING. Do not modify this method.
// Doing so will nullify your score for this activity.
void print_inorder(node* curr) {
if (curr->left != NULL) {
print_inorder(curr->left);
}
cout << curr->element << " ";
if (curr->right != NULL) {
print_inorder(curr->right);
}
}
// WARNING. Do not modify this method.
// Doing so will nullify your score for this activity.
bool check_health(node* curr, node* parent) {
bool health = curr->parent == parent;
if (curr->left != NULL) {
health &= check_health(curr->left, curr);
}
if (curr->right != NULL) {
health &= check_health(curr->right, curr);
}
return health;
}
};
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 5 steps with 5 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education