Question: C + + PLEASE 2 1 . 1 4 CIST 2 3 6 2 Lab: Binary Search Tree ( BST ) Containe This lab is
C PLEASE
CIST Lab: Binary Search Tree BST Containe
This lab is about building a simple Binary Search Tree Container. Your tasks are to complete the following member functions for the Tree class:
void insertconst T&: This function inserts a new value into the BST
TreeNode findconst T&: This function performs a BST search to determine if a value exists in the binary tree
void outputTree: This function outputs "Tree Empty" if there are no nodes in the tree. This function also uses a recursive helper function when there are nodes in the tree: void outputTreeHelperTreeNode
void outputTreeHelperTreeNode: This is a recursive function that traverses the BST inorder.
You should use the pseudocode in the chapter to provide guidance in writing each of these functions.
The main that is provided is a sample main that you can use to test class. When you submit, you will only be submitting the Tree.h file. The program expects to read a file of words and then inserts them into the BST The file may look like:
highway
difference
philosophy
quality
agency
The output for this input would be:
size of tree:
agency
difference
highway
philosophy
quality
MAIN.CPP
#include
#include
#include
#include "Tree.h
int main
Tree treeOfStrings;
std::ifstream inputFile;
std::string filename;
std::string inputData;
std::cin filename;
inputFile.openfilename;
while inputFile inputData
treeOfStrings.insertinputData;
std::cout "size of tree: treeOfStrings.size std::endl;
treeOfStrings.outputTree;
return ;
TREENODE.H
#ifndef LABLESSONTREESTREENODEH
#define LABLESSONTREESTREENODEH
template
class TreeNode
private:
T dataItem;
TreeNode left;
TreeNode right;
protected:
public:
TreeNodeT dataItem, TreeNode left nullptr, TreeNode right nullptr :
dataItemdataItem leftleft rightright
T getDataItem const;
void setDataItemT dataItem;
TreeNode getLeft const;
void setLeftTreeNode left;
TreeNode getRight const;
void setRightTreeNode right;
;
template
T TreeNode::getDataItem const
return dataItem;
template
void TreeNode::setDataItemT dataItem
TreeNode::dataItem dataItem;
template
TreeNode TreeNode::getLeft const
return left;
template
void TreeNode::setLeftTreeNode left
TreeNode::left left;
template
TreeNode TreeNode::getRight const
return right;
template
void TreeNode::setRightTreeNode right
TreeNode::right right;
#endif LABLESSONTREESTREENODEH
TREE.H
#ifndef LABLESSONTREESTREEH
#define LABLESSONTREESTREEH
#include
#include "TreeNode.h
template
class Tree
private:
TreeNode root;
unsigned int currentSize;
void outputTreeHelperTreeNode node;
protected:
public:
explicit TreeTreeNode root nullptr : rootroot currentSize
TreeNode getRoot const;
unsigned int size const;
void insertconst T&;
TreeNode findconst T&;
void outputTree;
;
template
TreeNode Tree::getRoot const
return root;
template
void Tree::insertconst T& dataItem
TODO: Complete this function
template
TreeNode Tree::findconst T& lookfor
TODO: Complete this function
return nullptr; Not found
template
void Tree::outputTree
if root nullptr
TODO: Complete code here
else
TODO: Complete code here
template
void Tree::outputTreeHelperTreeNode node
TODO: Complete this function
template
unsigned int Tree::size const
return currentSize;
#endif LABLESSONTREESTREEH
EXPERT ANSWER NEED EDIT. CODE IS RIGHT JUST NEED LINESPACING EDIT.
PLEASE PROVIDE LINESPACING EDIT FOR THIS NEW CODE OF TREE.H IN C
#ifndef LABLESSONTREESTREEH
#define LABLESSONTREESTREEH
#include
#include "TreeNode.h
Template class for a Binary Search Tree BST
template
class Tree
private:
TreeNode root; Pointer to the root node of the tree
unsigned int currentSize; Number of nodes in the tree
Recursive helper function to output the tree inorder
void outputTreeHelperTreeNode node
if node nullptr
outputTreeHelpernodegetLeft;
std::cout nodegetDataItem;
outputTreeHelpernodegetRight;
protected:
public:
Constructor for a new tree with an optional root node
explicit TreeTreeNode root nullptr : rootroot currentSize
Getter for the root node of the tree
TreeNode getRoot const return root;
Getter for the number of nodes in the tree
unsigned int size const return currentSize;
Output is nearly correct, but whi
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
