SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
1. (25 pts) Implement the insert method for binary search trees. Do not insert duplicate values. 2.
(15 pts) Implement the search method for binary search trees. 3. (15 pts) Implement isBST, a
method for checking whether or not a tree is a binary search tree. 4. (10 pts) Implement the pre-
order traversal method for binary search trees.
All of this should be implemented in the below code, in C++, without changing any of the
parameters or functions as they are laid out.
#include<iostream>
#include <vector>
#include <limits.h>
#include "BST.h"
BST::BST(){
}
BST::~BST(){}
std::shared_ptr<Node> BST::search(int target){
return nullptr;
}
std::shared_ptr<Node> BST::search(std::shared_ptr<Node> n, int target){
return nullptr;
}
std::shared_ptr<Node> BST::minimum(){
return nullptr;
}
std::shared_ptr<Node> BST::minimum(std::shared_ptr<Node> n){
return nullptr;
}
std::shared_ptr<Node> BST::maximum(){
return nullptr;
}
std::shared_ptr<Node> BST::maximum(std::shared_ptr<Node> n){
return nullptr;
}
void BST::insertValue(int val){
}
std::shared_ptr<Node> BST::insertValue(std::shared_ptr<Node> n, int val){
return nullptr;
}
void BST::deleteValue(int val){
}
std::shared_ptr<Node> BST::deleteValue(std::shared_ptr<Node> n, int val){
return nullptr;
}
bool BST::isBST(std::shared_ptr<Node> n){
return false;
}
bool BST::isBST(std::shared_ptr<Node> n, int low, int high){
return false;
}
void BST::preOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>>
&order){
}
void BST::inOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>>
&order){
}
void BST::postOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>>
&order){
}
The code above is meant to be grouped together with the below code:
BST.h:
// CSCI 311 - Spring 2023
// Lab 3 BST header
// Author: Carter Tillquist
#ifndef BST_H
#define BST_H
#include <memory>
#include <vector>
#include "Node.h"
class BST{
public:
std::shared_ptr<Node> root;
int size;
Node* left;
Node* right;
Node* data;
BST();
~BST();
std::shared_ptr<Node> search(int);
std::shared_ptr<Node> search(std::shared_ptr<Node>, int);
std::shared_ptr<Node> minimum();
std::shared_ptr<Node> minimum(std::shared_ptr<Node>);
std::shared_ptr<Node> maximum();
std::shared_ptr<Node> maximum(std::shared_ptr<Node>);
void insertValue(int);
std::shared_ptr<Node> insertValue(std::shared_ptr<Node>, int);
void deleteValue(int);
std::shared_ptr<Node> deleteValue(std::shared_ptr<Node>, int);
bool isBST(std::shared_ptr<Node>);
bool isBST(std::shared_ptr<Node>, int, int);
void preOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&);
void inOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&);
void postOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&);
};
#endif
Node.cpp:
// CSCI 311 - Spring 2023
// Node Class
// Author: Carter Tillquist
#include "Node.h"
Node::Node(){
value = 0;
left = nullptr;
right = nullptr;
}
Node::Node(int v){
value = v;
left = nullptr;
right = nullptr;
}
Node::~Node(){}
Node.h
// CSCI 311 - Spring 2023
// Node Header
// Author: Carter Tillquist
#ifndef NODE_H
#define NODE_H
#include <memory>
class Node{
public:
int value;
Node* left;
Node* right;
Node* data;
Node();
Node(int);
~Node();
};
#endif
BSTDriver.cpp
// CSCI 311 - Spring 2023
// Lab 3 - BST Driver
// Author: Carter Tillquist
#include <iostream>
#include <memory>
#include <vector>
#include "BST.h"
using namespace std;
void printVector(const vector<std::shared_ptr<Node>>& v);
void runSearch(std::shared_ptr<BST> T);
void runInsert(std::shared_ptr<BST> T);
void runDelete(std::shared_ptr<BST> T);
/**************************************************
* Simple main to test Binary Search Tree methods *
* ************************************************/
int main() {
std::shared_ptr<BST> T(new BST());
int operation;
cin >> operation;
while (operation > 0) {
vector<std::shared_ptr<Node>> order;
switch (operation) {
case 1: // search
cout << "SEARCH FOR ";
runSearch(T);
break;
case 2: // insert
cout << "INSERT ";
runInsert(T);
break;
case 3: // delete
cout << "DELETE ";
runDelete(T);
break;
case 4: // preorder
cout << "PREORDER" << endl;
T->preOrder(T->root, order);
printVector(order);
break;
case 5: // inorder
cout << "INORDER" << endl;
T->inOrder(T->root, order);
printVector(order);
break;
case 6: // postorder
cout << "POSTORDER" << endl;
T->postOrder(T->root, order);
printVector(order);
break;
case 7: // minimum
cout << "MINIMUM" << endl;
cout << T->minimum()->value << endl;
break;
case 8: // maximum
cout << "MAXIMUM" << endl;
cout << T->maximum()->value << endl;
break;
case 9: // is BST
cout << "IS BST" << endl;
cout << T->isBST(T->root) << endl;
break;
default:
break;
}
cin >> operation;
}
return 0;
}
/*****************************************************************
* Print the values of nodes in a vector *
* v - const vector<std::shared_ptr<Node>> & - a vector of Nodes *
* ***************************************************************/
void printVector(const vector<std::shared_ptr<Node>>& v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i]->value << " ";
}
cout << endl;
}
/*****************************************************************************
**************
* Given a BST, get a value to search for from the console and apply the BST search method *
* T - std::shared_ptr<BST> - a Binary Search Tree *
*
******************************************************************************
***********/
void runSearch(std::shared_ptr<BST> T) {
int target;
cin >> target;
cout << target << endl;
std::shared_ptr<Node> n = T->search(target);
if (n) { cout << n->value << endl; }
else { cout << "Not found" << endl; }
}
/********************************************************************
* Given a BST, get a value from the console and add it to the tree *
* T - std::shared_ptr<BST> - a Binary Search Tree *
* ******************************************************************/
void runInsert(std::shared_ptr<BST> T) {
int newVal;
cin >> newVal;
cout << newVal << endl;
T->insertValue(newVal);
}
/*****************************************************************************
*********
* Given a BST, get a value from the console and remove it from the tree if it exists *
* T - std::shared_ptr<BST> - a Binary Search Tree *
*
******************************************************************************
******/
void runDelete(std::shared_ptr<BST> T) {
int remove;
cin >> remove;
cout << remove << endl;
T->deleteValue(remove);
}

Weitere Àhnliche Inhalte

Ähnlich wie 1- (25 pts) Implement the insert method for binary search trees- Do no.pdf

Deductive verification of unmodified Linux kernel library functions
Deductive verification of unmodified Linux kernel library functionsDeductive verification of unmodified Linux kernel library functions
Deductive verification of unmodified Linux kernel library functionsDenis Efremov
 
pointers
pointerspointers
pointersteach4uin
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfhardjasonoco14599
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxShashiShash2
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxAbubakar524802
 
C++ Secure Programming
C++ Secure ProgrammingC++ Secure Programming
C++ Secure ProgrammingMarian Marinov
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - ReferenceMohammed Sikander
 
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒ
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒLook Ma, “update DB to HTML5 using C++”, no hands! ïżŒ
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒaleks-f
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
 
In c++ format please, for each function in the code, using the comme.pdf
In c++ format please, for each function in the code, using the comme.pdfIn c++ format please, for each function in the code, using the comme.pdf
In c++ format please, for each function in the code, using the comme.pdfezycolours78
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interviewRussell Childs
 

Ähnlich wie 1- (25 pts) Implement the insert method for binary search trees- Do no.pdf (20)

Deductive verification of unmodified Linux kernel library functions
Deductive verification of unmodified Linux kernel library functionsDeductive verification of unmodified Linux kernel library functions
Deductive verification of unmodified Linux kernel library functions
 
pointers
pointerspointers
pointers
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
C++ Secure Programming
C++ Secure ProgrammingC++ Secure Programming
C++ Secure Programming
 
Permute
PermutePermute
Permute
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒ
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒLook Ma, “update DB to HTML5 using C++”, no hands! ïżŒ
Look Ma, “update DB to HTML5 using C++”, no hands! ïżŒ
 
Permute
PermutePermute
Permute
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 
In c++ format please, for each function in the code, using the comme.pdf
In c++ format please, for each function in the code, using the comme.pdfIn c++ format please, for each function in the code, using the comme.pdf
In c++ format please, for each function in the code, using the comme.pdf
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interview
 

Mehr von AdrianEBJKingr

1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdfAdrianEBJKingr
 
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdfAdrianEBJKingr
 
1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdfAdrianEBJKingr
 
1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdfAdrianEBJKingr
 
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdfAdrianEBJKingr
 
1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdfAdrianEBJKingr
 
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdfAdrianEBJKingr
 
-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdfAdrianEBJKingr
 
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdfAdrianEBJKingr
 
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdfAdrianEBJKingr
 
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdfAdrianEBJKingr
 
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdfAdrianEBJKingr
 
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdfAdrianEBJKingr
 
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdfAdrianEBJKingr
 
--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdfAdrianEBJKingr
 
-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdfAdrianEBJKingr
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdfAdrianEBJKingr
 
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdfAdrianEBJKingr
 
1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdfAdrianEBJKingr
 

Mehr von AdrianEBJKingr (20)

1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
1- Answer the following characteristics for Chytridiomycota Fungi- A-.pdf
 
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
1- A TIPS has a coupon of 7-- paid semiannually- The current rate of i.pdf
 
1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf1- A General Right to Privacy was written explicitly into the US Const.pdf
1- A General Right to Privacy was written explicitly into the US Const.pdf
 
1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf1- A business has the following information for the year- Determine th.pdf
1- A business has the following information for the year- Determine th.pdf
 
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
1- -8 points- Write a MIPS code to compute the factorial of a positive.pdf
 
1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf1- (Aggregates) Consider an economy that is in below full employment e.pdf
1- (Aggregates) Consider an economy that is in below full employment e.pdf
 
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
1- (3 polats) O Suppose that A add B are ladepedbet ewnts- Furthemore-.pdf
 
-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf-The following information applies to the questions displayed below- O.pdf
-The following information applies to the questions displayed below- O.pdf
 
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
-NYP-- New York Paper Co-- is using its financial results for August 2.pdf
 
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
-Java lang- Q3 (10)- A program creates a queue- The program takes arra.pdf
 
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
-2-Cyanide is a highly fast-acting poison- In fact- it was developed a.pdf
 
-23-.pdf
-23-.pdf-23-.pdf
-23-.pdf
 
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
-begin{tabular}{l-l} cHALlenge -- ACriviry -end{tabular} 4-3-1- Confid.pdf
 
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
---BUS-- public class Bus { String busIdentifier- String driverName- d.pdf
 
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
-10 points- For each of the Regular Expression- draw FA recognizing th.pdf
 
--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf--What is wrong with this C++ program- -- # include iostream using nam.pdf
--What is wrong with this C++ program- -- # include iostream using nam.pdf
 
-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf-10 points- Construct minimized DFA accepting language represented by.pdf
-10 points- Construct minimized DFA accepting language represented by.pdf
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
 
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf--kindly help---Explain what happens when the PUSHA instruction execut.pdf
--kindly help---Explain what happens when the PUSHA instruction execut.pdf
 
1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf1)What is the most important benefit you believe students get from the.pdf
1)What is the most important benefit you believe students get from the.pdf
 

KĂŒrzlich hochgeladen

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...Nguyen Thanh Tu Collection
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

KĂŒrzlich hochgeladen (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
TỔNG ÔN TáșŹP THI VÀO LỚP 10 MÔN TIáșŸNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGở Â...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

1- (25 pts) Implement the insert method for binary search trees- Do no.pdf

  • 1. 1. (25 pts) Implement the insert method for binary search trees. Do not insert duplicate values. 2. (15 pts) Implement the search method for binary search trees. 3. (15 pts) Implement isBST, a method for checking whether or not a tree is a binary search tree. 4. (10 pts) Implement the pre- order traversal method for binary search trees. All of this should be implemented in the below code, in C++, without changing any of the parameters or functions as they are laid out. #include<iostream> #include <vector> #include <limits.h> #include "BST.h" BST::BST(){ } BST::~BST(){} std::shared_ptr<Node> BST::search(int target){ return nullptr; } std::shared_ptr<Node> BST::search(std::shared_ptr<Node> n, int target){ return nullptr; } std::shared_ptr<Node> BST::minimum(){ return nullptr; } std::shared_ptr<Node> BST::minimum(std::shared_ptr<Node> n){ return nullptr; } std::shared_ptr<Node> BST::maximum(){ return nullptr; } std::shared_ptr<Node> BST::maximum(std::shared_ptr<Node> n){ return nullptr; } void BST::insertValue(int val){ }
  • 2. std::shared_ptr<Node> BST::insertValue(std::shared_ptr<Node> n, int val){ return nullptr; } void BST::deleteValue(int val){ } std::shared_ptr<Node> BST::deleteValue(std::shared_ptr<Node> n, int val){ return nullptr; } bool BST::isBST(std::shared_ptr<Node> n){ return false; } bool BST::isBST(std::shared_ptr<Node> n, int low, int high){ return false; } void BST::preOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>> &order){ } void BST::inOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>> &order){ } void BST::postOrder(std::shared_ptr<Node> n, std::vector<std::shared_ptr<Node>> &order){ } The code above is meant to be grouped together with the below code: BST.h: // CSCI 311 - Spring 2023 // Lab 3 BST header // Author: Carter Tillquist #ifndef BST_H #define BST_H #include <memory> #include <vector> #include "Node.h"
  • 3. class BST{ public: std::shared_ptr<Node> root; int size; Node* left; Node* right; Node* data; BST(); ~BST(); std::shared_ptr<Node> search(int); std::shared_ptr<Node> search(std::shared_ptr<Node>, int); std::shared_ptr<Node> minimum(); std::shared_ptr<Node> minimum(std::shared_ptr<Node>); std::shared_ptr<Node> maximum(); std::shared_ptr<Node> maximum(std::shared_ptr<Node>); void insertValue(int); std::shared_ptr<Node> insertValue(std::shared_ptr<Node>, int); void deleteValue(int); std::shared_ptr<Node> deleteValue(std::shared_ptr<Node>, int); bool isBST(std::shared_ptr<Node>); bool isBST(std::shared_ptr<Node>, int, int); void preOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&); void inOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&); void postOrder(std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>&); }; #endif Node.cpp: // CSCI 311 - Spring 2023 // Node Class // Author: Carter Tillquist #include "Node.h" Node::Node(){ value = 0; left = nullptr;
  • 4. right = nullptr; } Node::Node(int v){ value = v; left = nullptr; right = nullptr; } Node::~Node(){} Node.h // CSCI 311 - Spring 2023 // Node Header // Author: Carter Tillquist #ifndef NODE_H #define NODE_H #include <memory> class Node{ public: int value; Node* left; Node* right; Node* data; Node(); Node(int); ~Node(); }; #endif BSTDriver.cpp // CSCI 311 - Spring 2023 // Lab 3 - BST Driver // Author: Carter Tillquist #include <iostream> #include <memory> #include <vector>
  • 5. #include "BST.h" using namespace std; void printVector(const vector<std::shared_ptr<Node>>& v); void runSearch(std::shared_ptr<BST> T); void runInsert(std::shared_ptr<BST> T); void runDelete(std::shared_ptr<BST> T); /************************************************** * Simple main to test Binary Search Tree methods * * ************************************************/ int main() { std::shared_ptr<BST> T(new BST()); int operation; cin >> operation; while (operation > 0) { vector<std::shared_ptr<Node>> order; switch (operation) { case 1: // search cout << "SEARCH FOR "; runSearch(T); break; case 2: // insert cout << "INSERT "; runInsert(T); break; case 3: // delete cout << "DELETE "; runDelete(T); break; case 4: // preorder cout << "PREORDER" << endl; T->preOrder(T->root, order); printVector(order); break; case 5: // inorder cout << "INORDER" << endl; T->inOrder(T->root, order); printVector(order); break; case 6: // postorder cout << "POSTORDER" << endl; T->postOrder(T->root, order); printVector(order);
  • 6. break; case 7: // minimum cout << "MINIMUM" << endl; cout << T->minimum()->value << endl; break; case 8: // maximum cout << "MAXIMUM" << endl; cout << T->maximum()->value << endl; break; case 9: // is BST cout << "IS BST" << endl; cout << T->isBST(T->root) << endl; break; default: break; } cin >> operation; } return 0; } /***************************************************************** * Print the values of nodes in a vector * * v - const vector<std::shared_ptr<Node>> & - a vector of Nodes * * ***************************************************************/ void printVector(const vector<std::shared_ptr<Node>>& v) { for (int i = 0; i < v.size(); i++) { cout << v[i]->value << " "; } cout << endl; } /***************************************************************************** ************** * Given a BST, get a value to search for from the console and apply the BST search method * * T - std::shared_ptr<BST> - a Binary Search Tree * * ****************************************************************************** ***********/ void runSearch(std::shared_ptr<BST> T) { int target; cin >> target; cout << target << endl; std::shared_ptr<Node> n = T->search(target); if (n) { cout << n->value << endl; }
  • 7. else { cout << "Not found" << endl; } } /******************************************************************** * Given a BST, get a value from the console and add it to the tree * * T - std::shared_ptr<BST> - a Binary Search Tree * * ******************************************************************/ void runInsert(std::shared_ptr<BST> T) { int newVal; cin >> newVal; cout << newVal << endl; T->insertValue(newVal); } /***************************************************************************** ********* * Given a BST, get a value from the console and remove it from the tree if it exists * * T - std::shared_ptr<BST> - a Binary Search Tree * * ****************************************************************************** ******/ void runDelete(std::shared_ptr<BST> T) { int remove; cin >> remove; cout << remove << endl; T->deleteValue(remove); }