SlideShare a Scribd company logo
1 of 9
mok/BinarySearchTree.h
#ifndef BINARY_SEARCH_TREE_H
#define BINARY_SEARCH_TREE_H
#include "TreeNode.h"
/*
Incomplete BST. We will fill this out more in future lectures.
*/
template <typename T>
class BinarySearchTree
{
private:
TreeNode<T> *_root = nullptr;
int _tree_size = 0;
protected:
virtual TreeNode<T> * addItemHelper(TreeNode<T> *root,
T item)
{
//BASE CASE: null root
if (root == nullptr)
{
//allocate new space, store value, then return.
root = new TreeNode<T>{};
root->setValue(item);
return root;
}
//RECURSIVE CASE: root is not null
if (item >= root->getValue())
{
//CASE 1: belongs on the right side of root
TreeNode<T> *right = addItemHelper(
root->getRightChild(),
item
);
//update right side with reconfigured state
root->setRightChild(right);
}
else
{
//CASE 2: belongs on the left side of root
TreeNode<T> *left = addItemHelper(
root->getLeftChild(),
item
);
root->setLeftChild(left);
}
return root;
}
public:
virtual void addItem(T value)
{
_root = addItemHelper(_root, value);
_tree_size++;
}
};
#endif // BINARY_SEARCH_TREE_H
mok/main.cpp
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include "StringSplitter.h"
#include "BinarySearchTree.h"
using namespace std;
void bstTest()
{
BinarySearchTree<int> bst{};
bst.addItem(10);
bst.addItem(5);
bst.addItem(2);
bst.addItem(3);
bst.addItem(20);
bst.addItem(15);
}
int main()
{
bstTest();
return 0;
}
mok/mok.cbp
mok/mok.layout
mok/StringSplitter.h
#ifndef STRING_SPLITTER_H
#define STRING_SPLITTER_H
#include <string>
#include <vector>
#include <queue>
using namespace std;
class StringSplitter
{
public:
//Breaks apart the supplied text based on the given delimiter
//static function do not affect the internal state
//(e.g. variables) of a given class instance
static queue<string> splitQ(string text, string delimiter)
{
//vectors are dynamically expanding arrays
queue<string> pieces;
//find the first delimiter
int location = text.find(delimiter);
//we are starting at the beginning of our string
int start = 0;
//go until we have no more delimiters
while (location != string::npos)
{
//add the current piece to our list of pieces
string piece = text.substr(start, location - start);
pieces.push(piece);
//update our index markers for the next round
start = location + 1;
location = text.find(delimiter, start);
}
//at the end of our loop, we're going to have one
trailing piece to take care of.
//handle that now.
string piece = text.substr(start, location - start);
pieces.push(piece);
//now, return the completed vector
return pieces;
}
};
#endif // STRING_SPLITTER_H
mok/TreeNode.h

More Related Content

Similar to mokBinarySearchTree.h#ifndef BINARY_SEARCH_TREE_H#define B.docx

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.pdframbagra74
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdfarjuncp10
 
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.pdfanton291
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfhadpadrrajeshh
 
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.pdfpetercoiffeur18
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfFootageetoffe16
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfangelfragranc
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfshyamsunder1211
 
In the class LinkedBinarySearchTree implement only the following metho.pdf
In the class LinkedBinarySearchTree implement only the following metho.pdfIn the class LinkedBinarySearchTree implement only the following metho.pdf
In the class LinkedBinarySearchTree implement only the following metho.pdfsidkucheria
 
8 chapter4 trees_bst
8 chapter4 trees_bst8 chapter4 trees_bst
8 chapter4 trees_bstSSE_AndyLi
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docxkantrajnee88
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfinfo334223
 
There is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfThere is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfDhanrajsolanki2091
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docxjeanettehully
 
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.pdfsudhirchourasia86
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxrock73
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 

Similar to mokBinarySearchTree.h#ifndef BINARY_SEARCH_TREE_H#define B.docx (20)

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
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.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
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.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
 
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdfAssignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
Assignment 9 (Parent reference for BST) Redefine TreeNode by adding .pdf
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
In the class LinkedBinarySearchTree implement only the following metho.pdf
In the class LinkedBinarySearchTree implement only the following metho.pdfIn the class LinkedBinarySearchTree implement only the following metho.pdf
In the class LinkedBinarySearchTree implement only the following metho.pdf
 
8 chapter4 trees_bst
8 chapter4 trees_bst8 chapter4 trees_bst
8 chapter4 trees_bst
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docx
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdf
 
There is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdfThere is BinarySearchTree class. When removing a node from a BST, we.pdf
There is BinarySearchTree class. When removing a node from a BST, we.pdf
 
Running Head Discussion Board .docx
Running Head Discussion Board                                  .docxRunning Head Discussion Board                                  .docx
Running Head Discussion Board .docx
 
Binary Tree
Binary  TreeBinary  Tree
Binary Tree
 
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
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 

More from gilpinleeanna

Name 1. The table shows the number of days per week, x, that 100.docx
Name 1. The table shows the number of days per week, x, that 100.docxName 1. The table shows the number of days per week, x, that 100.docx
Name 1. The table shows the number of days per week, x, that 100.docxgilpinleeanna
 
Name _____________________Date ________________________ESL.docx
Name  _____________________Date  ________________________ESL.docxName  _____________________Date  ________________________ESL.docx
Name _____________________Date ________________________ESL.docxgilpinleeanna
 
Name Bijapur Fort Year 1599 Location Bijapur city.docx
Name Bijapur Fort Year 1599 Location Bijapur city.docxName Bijapur Fort Year 1599 Location Bijapur city.docx
Name Bijapur Fort Year 1599 Location Bijapur city.docxgilpinleeanna
 
Name _______________________________ (Ex2 rework) CHM 33.docx
Name  _______________________________ (Ex2 rework) CHM 33.docxName  _______________________________ (Ex2 rework) CHM 33.docx
Name _______________________________ (Ex2 rework) CHM 33.docxgilpinleeanna
 
Name 1 Should Transportation Security Officers Be A.docx
Name 1 Should Transportation Security Officers Be A.docxName 1 Should Transportation Security Officers Be A.docx
Name 1 Should Transportation Security Officers Be A.docxgilpinleeanna
 
Name Don’t ForgetDate UNIT 3 TEST(The direct.docx
Name   Don’t ForgetDate       UNIT 3 TEST(The direct.docxName   Don’t ForgetDate       UNIT 3 TEST(The direct.docx
Name Don’t ForgetDate UNIT 3 TEST(The direct.docxgilpinleeanna
 
Name Add name hereConcept Matching From Disease to Treatmen.docx
Name  Add name hereConcept Matching From Disease to Treatmen.docxName  Add name hereConcept Matching From Disease to Treatmen.docx
Name Add name hereConcept Matching From Disease to Treatmen.docxgilpinleeanna
 
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docx
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docxName Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docx
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docxgilpinleeanna
 
Name Add name hereHIM 2214 Module 6 Medical Record Abstractin.docx
Name  Add name hereHIM 2214 Module 6 Medical Record Abstractin.docxName  Add name hereHIM 2214 Module 6 Medical Record Abstractin.docx
Name Add name hereHIM 2214 Module 6 Medical Record Abstractin.docxgilpinleeanna
 
Name Sophocles, AntigoneMain Characters Antigone, Cre.docx
Name    Sophocles, AntigoneMain Characters Antigone, Cre.docxName    Sophocles, AntigoneMain Characters Antigone, Cre.docx
Name Sophocles, AntigoneMain Characters Antigone, Cre.docxgilpinleeanna
 
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docx
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docxN4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docx
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docxgilpinleeanna
 
Name Habitable Zones – Student GuideExercisesPlease r.docx
Name  Habitable Zones – Student GuideExercisesPlease r.docxName  Habitable Zones – Student GuideExercisesPlease r.docx
Name Habitable Zones – Student GuideExercisesPlease r.docxgilpinleeanna
 
Name Class Date SKILL ACTIVITY Giving an Eff.docx
Name    Class    Date   SKILL ACTIVITY Giving an Eff.docxName    Class    Date   SKILL ACTIVITY Giving an Eff.docx
Name Class Date SKILL ACTIVITY Giving an Eff.docxgilpinleeanna
 
Name Speech Title I. Intro A) Atten.docx
Name  Speech Title    I. Intro  A) Atten.docxName  Speech Title    I. Intro  A) Atten.docx
Name Speech Title I. Intro A) Atten.docxgilpinleeanna
 
n engl j med 352;16www.nejm.org april 21, .docx
n engl j med 352;16www.nejm.org april 21, .docxn engl j med 352;16www.nejm.org april 21, .docx
n engl j med 352;16www.nejm.org april 21, .docxgilpinleeanna
 
Name Class Date HUMR 211 Spr.docx
Name     Class     Date    HUMR 211 Spr.docxName     Class     Date    HUMR 211 Spr.docx
Name Class Date HUMR 211 Spr.docxgilpinleeanna
 
NAME ----------------------------------- CLASS -------------- .docx
NAME ----------------------------------- CLASS -------------- .docxNAME ----------------------------------- CLASS -------------- .docx
NAME ----------------------------------- CLASS -------------- .docxgilpinleeanna
 
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docx
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docxNAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docx
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docxgilpinleeanna
 
Name Understanding by Design (UbD) TemplateStage 1—Desir.docx
Name  Understanding by Design (UbD) TemplateStage 1—Desir.docxName  Understanding by Design (UbD) TemplateStage 1—Desir.docx
Name Understanding by Design (UbD) TemplateStage 1—Desir.docxgilpinleeanna
 
Name MUS108 Music Cultures of the World .docx
Name              MUS108 Music Cultures of the World              .docxName              MUS108 Music Cultures of the World              .docx
Name MUS108 Music Cultures of the World .docxgilpinleeanna
 

More from gilpinleeanna (20)

Name 1. The table shows the number of days per week, x, that 100.docx
Name 1. The table shows the number of days per week, x, that 100.docxName 1. The table shows the number of days per week, x, that 100.docx
Name 1. The table shows the number of days per week, x, that 100.docx
 
Name _____________________Date ________________________ESL.docx
Name  _____________________Date  ________________________ESL.docxName  _____________________Date  ________________________ESL.docx
Name _____________________Date ________________________ESL.docx
 
Name Bijapur Fort Year 1599 Location Bijapur city.docx
Name Bijapur Fort Year 1599 Location Bijapur city.docxName Bijapur Fort Year 1599 Location Bijapur city.docx
Name Bijapur Fort Year 1599 Location Bijapur city.docx
 
Name _______________________________ (Ex2 rework) CHM 33.docx
Name  _______________________________ (Ex2 rework) CHM 33.docxName  _______________________________ (Ex2 rework) CHM 33.docx
Name _______________________________ (Ex2 rework) CHM 33.docx
 
Name 1 Should Transportation Security Officers Be A.docx
Name 1 Should Transportation Security Officers Be A.docxName 1 Should Transportation Security Officers Be A.docx
Name 1 Should Transportation Security Officers Be A.docx
 
Name Don’t ForgetDate UNIT 3 TEST(The direct.docx
Name   Don’t ForgetDate       UNIT 3 TEST(The direct.docxName   Don’t ForgetDate       UNIT 3 TEST(The direct.docx
Name Don’t ForgetDate UNIT 3 TEST(The direct.docx
 
Name Add name hereConcept Matching From Disease to Treatmen.docx
Name  Add name hereConcept Matching From Disease to Treatmen.docxName  Add name hereConcept Matching From Disease to Treatmen.docx
Name Add name hereConcept Matching From Disease to Treatmen.docx
 
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docx
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docxName Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docx
Name Abdulla AlsuwaidiITA 160Uncle VanyaMan has been en.docx
 
Name Add name hereHIM 2214 Module 6 Medical Record Abstractin.docx
Name  Add name hereHIM 2214 Module 6 Medical Record Abstractin.docxName  Add name hereHIM 2214 Module 6 Medical Record Abstractin.docx
Name Add name hereHIM 2214 Module 6 Medical Record Abstractin.docx
 
Name Sophocles, AntigoneMain Characters Antigone, Cre.docx
Name    Sophocles, AntigoneMain Characters Antigone, Cre.docxName    Sophocles, AntigoneMain Characters Antigone, Cre.docx
Name Sophocles, AntigoneMain Characters Antigone, Cre.docx
 
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docx
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docxN4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docx
N4455 Nursing Leadership and ManagementWeek 3 Assignment 1.docx
 
Name Habitable Zones – Student GuideExercisesPlease r.docx
Name  Habitable Zones – Student GuideExercisesPlease r.docxName  Habitable Zones – Student GuideExercisesPlease r.docx
Name Habitable Zones – Student GuideExercisesPlease r.docx
 
Name Class Date SKILL ACTIVITY Giving an Eff.docx
Name    Class    Date   SKILL ACTIVITY Giving an Eff.docxName    Class    Date   SKILL ACTIVITY Giving an Eff.docx
Name Class Date SKILL ACTIVITY Giving an Eff.docx
 
Name Speech Title I. Intro A) Atten.docx
Name  Speech Title    I. Intro  A) Atten.docxName  Speech Title    I. Intro  A) Atten.docx
Name Speech Title I. Intro A) Atten.docx
 
n engl j med 352;16www.nejm.org april 21, .docx
n engl j med 352;16www.nejm.org april 21, .docxn engl j med 352;16www.nejm.org april 21, .docx
n engl j med 352;16www.nejm.org april 21, .docx
 
Name Class Date HUMR 211 Spr.docx
Name     Class     Date    HUMR 211 Spr.docxName     Class     Date    HUMR 211 Spr.docx
Name Class Date HUMR 211 Spr.docx
 
NAME ----------------------------------- CLASS -------------- .docx
NAME ----------------------------------- CLASS -------------- .docxNAME ----------------------------------- CLASS -------------- .docx
NAME ----------------------------------- CLASS -------------- .docx
 
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docx
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docxNAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docx
NAHQ Code of Ethics and Standards of Practice ©Copyright 2011 .docx
 
Name Understanding by Design (UbD) TemplateStage 1—Desir.docx
Name  Understanding by Design (UbD) TemplateStage 1—Desir.docxName  Understanding by Design (UbD) TemplateStage 1—Desir.docx
Name Understanding by Design (UbD) TemplateStage 1—Desir.docx
 
Name MUS108 Music Cultures of the World .docx
Name              MUS108 Music Cultures of the World              .docxName              MUS108 Music Cultures of the World              .docx
Name MUS108 Music Cultures of the World .docx
 

Recently uploaded

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

mokBinarySearchTree.h#ifndef BINARY_SEARCH_TREE_H#define B.docx

  • 1. mok/BinarySearchTree.h #ifndef BINARY_SEARCH_TREE_H #define BINARY_SEARCH_TREE_H #include "TreeNode.h" /* Incomplete BST. We will fill this out more in future lectures. */ template <typename T> class BinarySearchTree { private: TreeNode<T> *_root = nullptr; int _tree_size = 0; protected:
  • 2. virtual TreeNode<T> * addItemHelper(TreeNode<T> *root, T item) { //BASE CASE: null root if (root == nullptr) { //allocate new space, store value, then return. root = new TreeNode<T>{}; root->setValue(item); return root; } //RECURSIVE CASE: root is not null if (item >= root->getValue()) { //CASE 1: belongs on the right side of root TreeNode<T> *right = addItemHelper( root->getRightChild(), item
  • 3. ); //update right side with reconfigured state root->setRightChild(right); } else { //CASE 2: belongs on the left side of root TreeNode<T> *left = addItemHelper( root->getLeftChild(), item ); root->setLeftChild(left); } return root; }
  • 4. public: virtual void addItem(T value) { _root = addItemHelper(_root, value); _tree_size++; } }; #endif // BINARY_SEARCH_TREE_H mok/main.cpp #include <iostream> #include <string> #include <vector> #include <queue> #include "StringSplitter.h" #include "BinarySearchTree.h"
  • 5. using namespace std; void bstTest() { BinarySearchTree<int> bst{}; bst.addItem(10); bst.addItem(5); bst.addItem(2); bst.addItem(3); bst.addItem(20); bst.addItem(15); } int main() { bstTest(); return 0;
  • 6. } mok/mok.cbp mok/mok.layout mok/StringSplitter.h #ifndef STRING_SPLITTER_H #define STRING_SPLITTER_H #include <string> #include <vector> #include <queue> using namespace std; class StringSplitter { public:
  • 7. //Breaks apart the supplied text based on the given delimiter //static function do not affect the internal state //(e.g. variables) of a given class instance static queue<string> splitQ(string text, string delimiter) { //vectors are dynamically expanding arrays queue<string> pieces; //find the first delimiter int location = text.find(delimiter); //we are starting at the beginning of our string int start = 0; //go until we have no more delimiters while (location != string::npos) {
  • 8. //add the current piece to our list of pieces string piece = text.substr(start, location - start); pieces.push(piece); //update our index markers for the next round start = location + 1; location = text.find(delimiter, start); } //at the end of our loop, we're going to have one trailing piece to take care of. //handle that now. string piece = text.substr(start, location - start); pieces.push(piece); //now, return the completed vector return pieces; }