SlideShare a Scribd company logo
In c++ format please, for each function in the code, using the comments fill in the function to
write the whole program.
#include
#include
using namespace std;
template
class BST
{
private:
struct Node
{
bstdata data;
Node* left;
Node* right;
Node(bstdata newdata): data(newdata), left(NULL), right(NULL) {}
};
typedef struct Node* NodePtr;
NodePtr root;
/**Private helper functions*/
void insertHelper(NodePtr root, bstdata value);
//private helper function for insert
//recursively inserts a value into the BST
void destructorHelper(NodePtr root);
//private helper function for the destructor
//recursively frees the memory in the BST
void inOrderPrintHelper(NodePtr root);
//private helper function for inOrderPrint
//recursively prints tree values in order from smallest to largest
void preOrderPrintHelper(NodePtr root);
//private helper function for preOrderPrint
//recursively prints tree values in preorder
void postOrderPrintHelper(NodePtr root);
//private helper function for postOrderPrint
//recursively prints tree values in postorder
/**Public functions*/
public:
BST();
//Instantiates a new Binary Search Tree
//post: a new Binary Search Tree object
~BST();
//frees the memory of the BST object
//All memory has been deallocated
bool isEmpty();
//determines whether the Binary Search Tree is empty
void insert(bstdata value);
//inserts a new value into the Binary Search Tree
//post: a new value inserted into the Binary Search Tree
bstdata getRoot();
//returns the value stored at the root of the Binary Search Tree
//pre: the Binary Search Tree is not empty
void inOrderPrint();
//calls the inOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
void preOrderPrint();
//calls the preOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
void postOrderPrint();
//calls the postOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
};
Solution
Below code is completed with the function prototypes :
#include
#include
using namespace std;
template
class BST
{
private:
struct Node
{
bstdata data;
Node* left;
Node* right;
Node(bstdata newdata): data(newdata), left(NULL), right(NULL) {}
};
typedef struct Node* NodePtr;
NodePtr root;
/**Private helper functions*/
void insertHelper(NodePtr root, bstdata value){
if(root==NULL)
{
NodePtr *newnode=new node;
newnode->data=value;
root=newnode;
}
else{
if(valuedata)
insertHelper(value,root->left);
else
insertHelper(value,root->right);
}
}
//private helper function for insert
//recursively inserts a value into the BST
void destructorHelper(NodePtr root);
//private helper function for the destructor
//recursively frees the memory in the BST
void inOrderPrintHelper(NodePtr root){
if (root != NULL)
{
inorder(root->left);
cout<data<right);
}
}
//private helper function for inOrderPrint
//recursively prints tree values in order from smallest to largest
void preOrderPrintHelper(NodePtr root){
if (root != NULL)
{
cout<data<left);
inorder(root->right);
}
}
//private helper function for preOrderPrint
//recursively prints tree values in preorder
void postOrderPrintHelper(NodePtr root){
if (root != NULL)
{
inorder(root->left);
inorder(root->right);
cout<data<data == value )//no duplicates allowed in BST
return false;
else if( ptr->data < value )
{
ptr = ptr->right;
}
else
{
ptr = ptr->left;
}
}
if( prev->data < value ) //to be added as right child?
prev->right= new Node(value) ;
else
prev->left= new Node(value) ;
}
}
//inserts a new value into the Binary Search Tree
//post: a new value inserted into the Binary Search Tree
bstdata getRoot(){
return root->data;
}
//returns the value stored at the root of the Binary Search Tree
//pre: the Binary Search Tree is not empty
void inOrderPrint(){
inOrderPrint(NodePtr root);
}
//calls the inOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
void preOrderPrint(){
preOrderPrintHelper(NodePtr root);
}
//calls the preOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
void postOrderPrint(){
postOrderPrintHelper(NodePtr root);
}
//calls the postOrderPrintHelper function to print out the values
//stored in the Binary Search Tree
//If the tree is empty, prints nothing
};

More Related Content

PDF
In c++ format, for each function in the code, please using the comme.pdf
PDF
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
PDF
Please write the C++ code that would display the exact same output a.pdf
PDF
MAINCPP include ltiostreamgt include ltstringgt u.pdf
PDF
Help implement BST- The code must follow the instruction below as well.pdf
PDF
create a binary search tree from an empty one by adding the key valu.pdf
PDF
Help to implement delete_node get_succ get_pred walk and.pdf
PDF
This is a c++ binary search program I worked so far but still cant g.pdf
In c++ format, for each function in the code, please using the comme.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
Please write the C++ code that would display the exact same output a.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
Help implement BST- The code must follow the instruction below as well.pdf
create a binary search tree from an empty one by adding the key valu.pdf
Help to implement delete_node get_succ get_pred walk and.pdf
This is a c++ binary search program I worked so far but still cant g.pdf

Similar to In c++ format please, for each function in the code, using the comme.pdf (20)

PDF
Write a C++ program that implements a binary search tree (BST) to man.pdf
PDF
Implement a function TNode copy_tree(TNode t) that creates a copy .pdf
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
DOCX
Complete the C++ program and implement the routines that are n.docx
PDF
Below binary program is usefell to you#include iostreamtem.pdf
PDF
I have C++ question that I do not know how to do, Can you teach me t.pdf
PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
PPT
Unit8 C
PDF
In C++ Follow all code styling and submission instructions a.pdf
PDF
Tree Traversals A tree traversal is the process of visiting.pdf
PDF
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
PPTX
Binary Search Tree.pptxA binary search i
PDF
Tree and binary tree
Write a C++ program that implements a binary search tree (BST) to man.pdf
Implement a function TNode copy_tree(TNode t) that creates a copy .pdf
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
Below binary program is usefell to you#include iostreamtem.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
Unit8 C
In C++ Follow all code styling and submission instructions a.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
Binary Search Tree.pptxA binary search i
Tree and binary tree

More from ezycolours78 (20)

PDF
Find the rate 32. of change in luxury purchases in China with respect.pdf
PDF
Given f(x) = x^2x^2 + 3 Find (a) the domain and range of f, (b) the.pdf
PDF
Help with Starting out with visual basic 7th edition chapter 6 Progr.pdf
PDF
Give short answers for the following questionsi.Define ‘Accountin.pdf
PDF
For the reaction NO+03--NO2+O2, the reaction was found to be first .pdf
PDF
Discuss how you would go about setting up a human source collection .pdf
PDF
Describe how meiotic and mitotic nondisjunctions occur and their pos.pdf
PDF
CASE 16 Southwest Airlines Andrew Inkpen and ex.pdf
PDF
An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
PDF
6. Edit the following for the format of a reference listREFERENCE.pdf
PDF
2.Distinguish between assigned and emergent leaders. Give an example.pdf
PDF
3. What lines of evidence do we have that evolution has taken place.pdf
PDF
4. Where in your home would endospores most likely be found Wh b. .pdf
PDF
25. Radium is called a _________ and replaces calcium in bones and c.pdf
PDF
What skills does law enforcement need to combat cyber crimesSol.pdf
PDF
Using Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdf
PDF
were CPA involved in Enron scandal act with integrity as defined by .pdf
PDF
16) What are the two types of current What is different about the fl.pdf
PDF
What are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdf
PDF
To complete the task, you need to fill in the missing code. I’ve inc.pdf
Find the rate 32. of change in luxury purchases in China with respect.pdf
Given f(x) = x^2x^2 + 3 Find (a) the domain and range of f, (b) the.pdf
Help with Starting out with visual basic 7th edition chapter 6 Progr.pdf
Give short answers for the following questionsi.Define ‘Accountin.pdf
For the reaction NO+03--NO2+O2, the reaction was found to be first .pdf
Discuss how you would go about setting up a human source collection .pdf
Describe how meiotic and mitotic nondisjunctions occur and their pos.pdf
CASE 16 Southwest Airlines Andrew Inkpen and ex.pdf
An epic bribe scandal at Petrobras, a major oil company controlled b.pdf
6. Edit the following for the format of a reference listREFERENCE.pdf
2.Distinguish between assigned and emergent leaders. Give an example.pdf
3. What lines of evidence do we have that evolution has taken place.pdf
4. Where in your home would endospores most likely be found Wh b. .pdf
25. Radium is called a _________ and replaces calcium in bones and c.pdf
What skills does law enforcement need to combat cyber crimesSol.pdf
Using Microsoft Visual Basics (.NET) ONLY!(This assignment encompa.pdf
were CPA involved in Enron scandal act with integrity as defined by .pdf
16) What are the two types of current What is different about the fl.pdf
What are some weakness of the NERC standard CPS1 and CPS2.Please lis.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
RMMM.pdf make it easy to upload and study
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Basic Mud Logging Guide for educational purpose
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Renaissance Architecture: A Journey from Faith to Humanism
RMMM.pdf make it easy to upload and study
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Pharma ospi slides which help in ospi learning
Basic Mud Logging Guide for educational purpose
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Supply Chain Operations Speaking Notes -ICLT Program
Institutional Correction lecture only . . .

In c++ format please, for each function in the code, using the comme.pdf

  • 1. In c++ format please, for each function in the code, using the comments fill in the function to write the whole program. #include #include using namespace std; template class BST { private: struct Node { bstdata data; Node* left; Node* right; Node(bstdata newdata): data(newdata), left(NULL), right(NULL) {} }; typedef struct Node* NodePtr; NodePtr root; /**Private helper functions*/ void insertHelper(NodePtr root, bstdata value); //private helper function for insert //recursively inserts a value into the BST void destructorHelper(NodePtr root); //private helper function for the destructor //recursively frees the memory in the BST void inOrderPrintHelper(NodePtr root);
  • 2. //private helper function for inOrderPrint //recursively prints tree values in order from smallest to largest void preOrderPrintHelper(NodePtr root); //private helper function for preOrderPrint //recursively prints tree values in preorder void postOrderPrintHelper(NodePtr root); //private helper function for postOrderPrint //recursively prints tree values in postorder /**Public functions*/ public: BST(); //Instantiates a new Binary Search Tree //post: a new Binary Search Tree object ~BST(); //frees the memory of the BST object //All memory has been deallocated bool isEmpty(); //determines whether the Binary Search Tree is empty void insert(bstdata value); //inserts a new value into the Binary Search Tree //post: a new value inserted into the Binary Search Tree bstdata getRoot(); //returns the value stored at the root of the Binary Search Tree //pre: the Binary Search Tree is not empty void inOrderPrint(); //calls the inOrderPrintHelper function to print out the values //stored in the Binary Search Tree
  • 3. //If the tree is empty, prints nothing void preOrderPrint(); //calls the preOrderPrintHelper function to print out the values //stored in the Binary Search Tree //If the tree is empty, prints nothing void postOrderPrint(); //calls the postOrderPrintHelper function to print out the values //stored in the Binary Search Tree //If the tree is empty, prints nothing }; Solution Below code is completed with the function prototypes : #include #include using namespace std; template class BST { private: struct Node { bstdata data; Node* left; Node* right; Node(bstdata newdata): data(newdata), left(NULL), right(NULL) {} }; typedef struct Node* NodePtr; NodePtr root; /**Private helper functions*/ void insertHelper(NodePtr root, bstdata value){
  • 4. if(root==NULL) { NodePtr *newnode=new node; newnode->data=value; root=newnode; } else{ if(valuedata) insertHelper(value,root->left); else insertHelper(value,root->right); } } //private helper function for insert //recursively inserts a value into the BST void destructorHelper(NodePtr root); //private helper function for the destructor //recursively frees the memory in the BST void inOrderPrintHelper(NodePtr root){ if (root != NULL) { inorder(root->left); cout<data<right); } } //private helper function for inOrderPrint //recursively prints tree values in order from smallest to largest void preOrderPrintHelper(NodePtr root){ if (root != NULL) { cout<data<left);
  • 5. inorder(root->right); } } //private helper function for preOrderPrint //recursively prints tree values in preorder void postOrderPrintHelper(NodePtr root){ if (root != NULL) { inorder(root->left); inorder(root->right); cout<data<data == value )//no duplicates allowed in BST return false; else if( ptr->data < value ) { ptr = ptr->right; } else { ptr = ptr->left; } } if( prev->data < value ) //to be added as right child? prev->right= new Node(value) ; else prev->left= new Node(value) ; } } //inserts a new value into the Binary Search Tree //post: a new value inserted into the Binary Search Tree bstdata getRoot(){ return root->data;
  • 6. } //returns the value stored at the root of the Binary Search Tree //pre: the Binary Search Tree is not empty void inOrderPrint(){ inOrderPrint(NodePtr root); } //calls the inOrderPrintHelper function to print out the values //stored in the Binary Search Tree //If the tree is empty, prints nothing void preOrderPrint(){ preOrderPrintHelper(NodePtr root); } //calls the preOrderPrintHelper function to print out the values //stored in the Binary Search Tree //If the tree is empty, prints nothing void postOrderPrint(){ postOrderPrintHelper(NodePtr root); } //calls the postOrderPrintHelper function to print out the values //stored in the Binary Search Tree //If the tree is empty, prints nothing };