SlideShare a Scribd company logo
Help to implement delete_node, get_succ, get_pred, walk, and tree_search in the script
following the given structure:
#include "bst.h"
// ---------------------------------------
// Node class
// Default constructor
Node::Node() {
// TODO: Implement this
key = 0;
parent = nullptr;
left = nullptr;
right = nullptr;
}
// Constructor
Node::Node(int in) {
// TODO: Implement this
key = in;
parent = nullptr;
left = nullptr;
right = nullptr;
}
// Destructor
Node::~Node() {
// TODO: Implement this
delete left;
delete right;
}
// Add parent
void Node::add_parent(Node* in) {
// TODO: Implement this
parent = in;
}
// Add to left of current node
void Node::add_left(Node* in) {
// TODO: Implement this
left = in;
if (in != nullptr) {
in->add_parent(this);
}
}
// Add to right of current node
void Node::add_right(Node* in) {
// TODO: Implement this
right = in;
if (in != nullptr) {
in->add_parent(this);
}
}
// Get key
int Node::get_key()
{
// TODO: Implement this
return key;
}
// Get parent node
Node* Node::get_parent()
{
// TODO: Implement this
return parent;
}
// Get left node
Node* Node::get_left()
{
// TODO: Implement this
return left;
}
// Get right node
Node* Node::get_right()
{
// TODO: Implement this
return right;
}
// Print the key to ostream to
// Do not change this
void Node::print_info(ostream& to)
{
to << key << endl;
}
// ---------------------------------------
// ---------------------------------------
// BST class
// Walk the subtree from the given node
void BST::inorder_walk(Node* in, ostream& to)
{
// TODO: Implement this
if (in != nullptr) {
inorder_walk(in->get_left(), to);
in->print_info(to);
inorder_walk(in->get_right(), to);
}
}
// Constructor
BST::BST()
{
// TODO: Implement this
root = nullptr;
}
// Destructor
BST::~BST()
{
// TODO: Implement this
delete root;
}
// Insert a node to the subtree
void BST::insert_node(Node* in)
{
// TODO: Implement this
Node* curr = root;
Node* par = nullptr;
while (curr != nullptr) {
par = curr;
if (in->get_key() < curr->get_key()) {
curr = curr->get_left();
} else {
curr = curr->get_right();
}
}
in->add_parent(par);
if (par == nullptr) {
root = in;
} else if (in->get_key() < par->get_key()) {
par->add_left(in);
} else {
par->add_right(in);
}
}
// Delete a node to the subtree
void BST::delete_node(Node* out)
{
// TODO: Implement this
}
// minimum key in the BST
Node* BST::tree_min()
{
// TODO: Implement this
return get_min(root);
}
// maximum key in the BST
Node* BST::tree_max()
{
// TODO: Implement this
return get_max(root);
}
// Get the minimum node from the subtree of given node
Node* BST::get_min(Node* in)
{
// TODO: Implement this
if (in == nullptr) {
return nullptr;
}
while (in->get_left() != nullptr) {
in = in->get_left();
}
return in;
}
// Get the maximum node from the subtree of given node
Node* BST::get_max(Node* in)
{
// TODO: Implement this
if (in == nullptr) {
return nullptr;
}
while (in->get_right() != nullptr) {
in = in->get_right();
}
return in;
}
// Get successor of the given node
Node* BST::get_succ(Node* in)
{
// TODO: Implement this
}
// Get predecessor of the given node
Node* BST::get_pred(Node* in)
{
// TODO: Implement this
}
// Walk the BST from min to max
void BST::walk(ostream& to)
{
// TODO: Implement this
}
// Search the tree for a given key
Node* BST::tree_search(int search_key)
{
// TODO: Implement this
}
// ---------------------------------------
bst.h
#ifndef BST_H_
#define BST_H_
#include <iostream>
using namespace std;
class Node {
private:
int key;
Node* parent;
Node* left;
Node* right;
public:
// Default constructor
Node();
// Constructor
Node(int in);
// Destructor
// a virtual constructor is required for inheritance
virtual ~Node();
// Add to parent of current node
void add_parent(Node* in);
// Add to left of current node
void add_left(Node* in);
// Add to right of current node
void add_right(Node* in);
// Get key
int get_key();
// Get parent node
Node* get_parent();
// Get left node
Node* get_left();
// Get right node
Node* get_right();
virtual void print_info(ostream& to);
};
class BST {
private:
Node* root;
// Walk the subtree from the given node
void inorder_walk(Node* in, ostream& to);
// Get the minimum node from the subtree of given node
Node* get_min(Node* in);
// Get the maximum node from the subtree of given node
Node* get_max(Node* in);
public:
// Constructor and Destructor
BST();
~BST();
// Modify tree
void insert_node(Node* in);
void delete_node(Node* out);
// Find nodes in the tree
Node* tree_min(); // minimum key value
Node* tree_max(); // maximum key value
Node* get_succ(Node* in); // successor for a given node
Node* get_pred(Node* in); // predecessor for a given node
void walk(ostream& to); // Traverse the tree from min to max recursively
Node* tree_search(int search_key);
};
#endif

More Related Content

Similar to Help to implement delete_node get_succ get_pred walk and.pdf

Templated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdfTemplated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdf
manjan6
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdfC++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
rohit219406
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
rambagra74
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
ZarghamullahShah
 
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptxData Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
RashidFaridChishti
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
arpitcomputronics
 
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
petercoiffeur18
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
anton291
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
sudhirchourasia86
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
budbarber38650
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
excellentmobilesabc
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdf
amarndsons
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
arjunenterprises1978
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
indiaartz
 
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdfmain.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
pratikradia365
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
shanki7
 

Similar to Help to implement delete_node get_succ get_pred walk and.pdf (20)

Templated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdfTemplated Binary Tree implementing function help I need to im.pdf
Templated Binary Tree implementing function help I need to im.pdf
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdfC++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptxData Structures and Agorithm: DS 14 Binary Expression Tree.pptx
Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
 
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
1)(JAVA) Extend the Binary Search Tree ADT to include a public metho.pdf
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdf
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
 
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdfmain.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 

More from contact32

From the following list of accounts calculate the quick rati.pdf
From the following list of accounts calculate the quick rati.pdfFrom the following list of accounts calculate the quick rati.pdf
From the following list of accounts calculate the quick rati.pdf
contact32
 
Errors are defined as An injury caused by medical managemen.pdf
Errors are defined as An injury caused by medical managemen.pdfErrors are defined as An injury caused by medical managemen.pdf
Errors are defined as An injury caused by medical managemen.pdf
contact32
 
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdfESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
contact32
 
Deliverables Your deliverable in this assignment is to d.pdf
Deliverables Your deliverable in this assignment is to  d.pdfDeliverables Your deliverable in this assignment is to  d.pdf
Deliverables Your deliverable in this assignment is to d.pdf
contact32
 
Diana and Ryan Workman were married on January 1 of last yea.pdf
Diana and Ryan Workman were married on January 1 of last yea.pdfDiana and Ryan Workman were married on January 1 of last yea.pdf
Diana and Ryan Workman were married on January 1 of last yea.pdf
contact32
 
6 15 points Let Ntt0 be a Poisson process with rate .pdf
6 15 points Let Ntt0 be a Poisson process with rate .pdf6 15 points Let Ntt0 be a Poisson process with rate .pdf
6 15 points Let Ntt0 be a Poisson process with rate .pdf
contact32
 
Bario Corporation ha proporcionado los siguientes datos sobr.pdf
Bario Corporation ha proporcionado los siguientes datos sobr.pdfBario Corporation ha proporcionado los siguientes datos sobr.pdf
Bario Corporation ha proporcionado los siguientes datos sobr.pdf
contact32
 
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdfCaratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
contact32
 
A function annotation also known as a type hint serves to .pdf
A function annotation also known as a type hint serves to .pdfA function annotation also known as a type hint serves to .pdf
A function annotation also known as a type hint serves to .pdf
contact32
 
Beckenworth had the following purchases and sales during the.pdf
Beckenworth had the following purchases and sales during the.pdfBeckenworth had the following purchases and sales during the.pdf
Beckenworth had the following purchases and sales during the.pdf
contact32
 
Part 1 True or False 16 marks Write True or false for th.pdf
Part 1 True or False 16 marks Write True or false for th.pdfPart 1 True or False 16 marks Write True or false for th.pdf
Part 1 True or False 16 marks Write True or false for th.pdf
contact32
 
Which of the following is the correct sequence for the germi.pdf
Which of the following is the correct sequence for the germi.pdfWhich of the following is the correct sequence for the germi.pdf
Which of the following is the correct sequence for the germi.pdf
contact32
 
Oriole Corporation issues 340000 of bonds for 343400 a.pdf
Oriole Corporation issues 340000 of bonds for 343400 a.pdfOriole Corporation issues 340000 of bonds for 343400 a.pdf
Oriole Corporation issues 340000 of bonds for 343400 a.pdf
contact32
 
You and a team of diverse scientists and astronauts have bee.pdf
You and a team of diverse scientists and astronauts have bee.pdfYou and a team of diverse scientists and astronauts have bee.pdf
You and a team of diverse scientists and astronauts have bee.pdf
contact32
 
You are working to your full scope as a Certificate IV gradu.pdf
You are working to your full scope as a Certificate IV gradu.pdfYou are working to your full scope as a Certificate IV gradu.pdf
You are working to your full scope as a Certificate IV gradu.pdf
contact32
 
Teresa has a deck of 10 cards numbered 1 through 10 She is.pdf
Teresa has a deck of 10 cards numbered 1 through 10  She is.pdfTeresa has a deck of 10 cards numbered 1 through 10  She is.pdf
Teresa has a deck of 10 cards numbered 1 through 10 She is.pdf
contact32
 
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdfTore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
contact32
 
What gets said if I run the script below The variable globa.pdf
What gets said if I run the script below The variable globa.pdfWhat gets said if I run the script below The variable globa.pdf
What gets said if I run the script below The variable globa.pdf
contact32
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
contact32
 

More from contact32 (20)

From the following list of accounts calculate the quick rati.pdf
From the following list of accounts calculate the quick rati.pdfFrom the following list of accounts calculate the quick rati.pdf
From the following list of accounts calculate the quick rati.pdf
 
Errors are defined as An injury caused by medical managemen.pdf
Errors are defined as An injury caused by medical managemen.pdfErrors are defined as An injury caused by medical managemen.pdf
Errors are defined as An injury caused by medical managemen.pdf
 
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdfESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
ESTUDIO DE CASO SNCLAVALIN GROUP INC Por Steven L McShan.pdf
 
Deliverables Your deliverable in this assignment is to d.pdf
Deliverables Your deliverable in this assignment is to  d.pdfDeliverables Your deliverable in this assignment is to  d.pdf
Deliverables Your deliverable in this assignment is to d.pdf
 
Diana and Ryan Workman were married on January 1 of last yea.pdf
Diana and Ryan Workman were married on January 1 of last yea.pdfDiana and Ryan Workman were married on January 1 of last yea.pdf
Diana and Ryan Workman were married on January 1 of last yea.pdf
 
6 15 points Let Ntt0 be a Poisson process with rate .pdf
6 15 points Let Ntt0 be a Poisson process with rate .pdf6 15 points Let Ntt0 be a Poisson process with rate .pdf
6 15 points Let Ntt0 be a Poisson process with rate .pdf
 
Bario Corporation ha proporcionado los siguientes datos sobr.pdf
Bario Corporation ha proporcionado los siguientes datos sobr.pdfBario Corporation ha proporcionado los siguientes datos sobr.pdf
Bario Corporation ha proporcionado los siguientes datos sobr.pdf
 
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdfCaratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
Caratinin 2 it Yoe may alos amune the itadaiand joypertin o.pdf
 
A function annotation also known as a type hint serves to .pdf
A function annotation also known as a type hint serves to .pdfA function annotation also known as a type hint serves to .pdf
A function annotation also known as a type hint serves to .pdf
 
Beckenworth had the following purchases and sales during the.pdf
Beckenworth had the following purchases and sales during the.pdfBeckenworth had the following purchases and sales during the.pdf
Beckenworth had the following purchases and sales during the.pdf
 
Part 1 True or False 16 marks Write True or false for th.pdf
Part 1 True or False 16 marks Write True or false for th.pdfPart 1 True or False 16 marks Write True or false for th.pdf
Part 1 True or False 16 marks Write True or false for th.pdf
 
Which of the following is the correct sequence for the germi.pdf
Which of the following is the correct sequence for the germi.pdfWhich of the following is the correct sequence for the germi.pdf
Which of the following is the correct sequence for the germi.pdf
 
Oriole Corporation issues 340000 of bonds for 343400 a.pdf
Oriole Corporation issues 340000 of bonds for 343400 a.pdfOriole Corporation issues 340000 of bonds for 343400 a.pdf
Oriole Corporation issues 340000 of bonds for 343400 a.pdf
 
You and a team of diverse scientists and astronauts have bee.pdf
You and a team of diverse scientists and astronauts have bee.pdfYou and a team of diverse scientists and astronauts have bee.pdf
You and a team of diverse scientists and astronauts have bee.pdf
 
You are working to your full scope as a Certificate IV gradu.pdf
You are working to your full scope as a Certificate IV gradu.pdfYou are working to your full scope as a Certificate IV gradu.pdf
You are working to your full scope as a Certificate IV gradu.pdf
 
Teresa has a deck of 10 cards numbered 1 through 10 She is.pdf
Teresa has a deck of 10 cards numbered 1 through 10  She is.pdfTeresa has a deck of 10 cards numbered 1 through 10  She is.pdf
Teresa has a deck of 10 cards numbered 1 through 10 She is.pdf
 
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdfTore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
Tore ne to the irrit Blued fequiredb Eupeoce that Chajs.pdf
 
What gets said if I run the script below The variable globa.pdf
What gets said if I run the script below The variable globa.pdfWhat gets said if I run the script below The variable globa.pdf
What gets said if I run the script below The variable globa.pdf
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
21 Ribozom antlamas ve dahili ribozom balangcnn ortak nokta.pdf
 

Recently uploaded

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

Help to implement delete_node get_succ get_pred walk and.pdf

  • 1. Help to implement delete_node, get_succ, get_pred, walk, and tree_search in the script following the given structure: #include "bst.h" // --------------------------------------- // Node class // Default constructor Node::Node() { // TODO: Implement this key = 0; parent = nullptr; left = nullptr; right = nullptr; } // Constructor Node::Node(int in) { // TODO: Implement this key = in; parent = nullptr; left = nullptr; right = nullptr; } // Destructor Node::~Node() { // TODO: Implement this delete left; delete right; } // Add parent void Node::add_parent(Node* in) { // TODO: Implement this parent = in; } // Add to left of current node void Node::add_left(Node* in) { // TODO: Implement this left = in; if (in != nullptr) { in->add_parent(this); } } // Add to right of current node void Node::add_right(Node* in) {
  • 2. // TODO: Implement this right = in; if (in != nullptr) { in->add_parent(this); } } // Get key int Node::get_key() { // TODO: Implement this return key; } // Get parent node Node* Node::get_parent() { // TODO: Implement this return parent; } // Get left node Node* Node::get_left() { // TODO: Implement this return left; } // Get right node Node* Node::get_right() { // TODO: Implement this return right; } // Print the key to ostream to // Do not change this void Node::print_info(ostream& to) { to << key << endl; } // --------------------------------------- // --------------------------------------- // BST class // Walk the subtree from the given node void BST::inorder_walk(Node* in, ostream& to)
  • 3. { // TODO: Implement this if (in != nullptr) { inorder_walk(in->get_left(), to); in->print_info(to); inorder_walk(in->get_right(), to); } } // Constructor BST::BST() { // TODO: Implement this root = nullptr; } // Destructor BST::~BST() { // TODO: Implement this delete root; } // Insert a node to the subtree void BST::insert_node(Node* in) { // TODO: Implement this Node* curr = root; Node* par = nullptr; while (curr != nullptr) { par = curr; if (in->get_key() < curr->get_key()) { curr = curr->get_left(); } else { curr = curr->get_right(); } } in->add_parent(par); if (par == nullptr) { root = in; } else if (in->get_key() < par->get_key()) { par->add_left(in); } else { par->add_right(in); }
  • 4. } // Delete a node to the subtree void BST::delete_node(Node* out) { // TODO: Implement this } // minimum key in the BST Node* BST::tree_min() { // TODO: Implement this return get_min(root); } // maximum key in the BST Node* BST::tree_max() { // TODO: Implement this return get_max(root); } // Get the minimum node from the subtree of given node Node* BST::get_min(Node* in) { // TODO: Implement this if (in == nullptr) { return nullptr; } while (in->get_left() != nullptr) { in = in->get_left(); } return in; } // Get the maximum node from the subtree of given node Node* BST::get_max(Node* in) { // TODO: Implement this if (in == nullptr) { return nullptr; } while (in->get_right() != nullptr) { in = in->get_right(); } return in; }
  • 5. // Get successor of the given node Node* BST::get_succ(Node* in) { // TODO: Implement this } // Get predecessor of the given node Node* BST::get_pred(Node* in) { // TODO: Implement this } // Walk the BST from min to max void BST::walk(ostream& to) { // TODO: Implement this } // Search the tree for a given key Node* BST::tree_search(int search_key) { // TODO: Implement this } // --------------------------------------- bst.h #ifndef BST_H_ #define BST_H_ #include <iostream> using namespace std; class Node { private: int key; Node* parent; Node* left; Node* right; public: // Default constructor Node(); // Constructor Node(int in); // Destructor // a virtual constructor is required for inheritance virtual ~Node(); // Add to parent of current node void add_parent(Node* in);
  • 6. // Add to left of current node void add_left(Node* in); // Add to right of current node void add_right(Node* in); // Get key int get_key(); // Get parent node Node* get_parent(); // Get left node Node* get_left(); // Get right node Node* get_right(); virtual void print_info(ostream& to); }; class BST { private: Node* root; // Walk the subtree from the given node void inorder_walk(Node* in, ostream& to); // Get the minimum node from the subtree of given node Node* get_min(Node* in); // Get the maximum node from the subtree of given node Node* get_max(Node* in); public: // Constructor and Destructor BST(); ~BST(); // Modify tree void insert_node(Node* in); void delete_node(Node* out); // Find nodes in the tree Node* tree_min(); // minimum key value Node* tree_max(); // maximum key value Node* get_succ(Node* in); // successor for a given node Node* get_pred(Node* in); // predecessor for a given node void walk(ostream& to); // Traverse the tree from min to max recursively Node* tree_search(int search_key); }; #endif