Question: C + + Visual Studio. Same Tree Function. Create a function called bool isSameTree ( Tree * ) ; that will take an argument of
C Visual Studio. Same Tree Function. Create a function called bool isSameTreeTree ; that will take an argument of a tree. It will return a true if the argument is the equivalent tree.
So for example, if we have two trees,
insertabc;
insertdef;
insertghi;
insertdef;
insertabc;
insertghi;
These two trees, even though they have different structures, are equivalent, and should return true.
If we compare these two trees:
insertabc;
insertghi;
insertabc;
insertdef;
insertghi;
They will return a false when sent to the function.
The program already has the files: BinaryTreeInterface.h BinaryNode.h BinaryNode.cpp BinaryNodeTree.h BinaryNodeTree.cpp NotFoundException.h PrecondViolatedExcept.h BinarySearchTree.h and BinarySearchTree.cpp In other words I need to implement the Same Tree Function in the driver, or source file. I would appreciate a practical example using the below methods as the basis and I would greatly appreciate comments. Please include trees in total. that are equivalent and return true and two that are not equivalent and return false. BinaryNodeTree has getRootData and BinaryNode has GetLeftChildPtrGetRightChildPtr It must use a string in the isSameTree function as it must be the same three letter combinations above.
BinaryNode Methods:
BinaryNode;
BinaryNodeconst ItemType& anItem;
BinaryNodeconst ItemType& anItem, std::sharedptr leftPtr, std::sharedptr rightPtr;
void setItemconst ItemType& anItem;
ItemType getItem const;
bool isLeaf const;
auto getLeftChildPtr const;
auto getRightChildPtr const;
void setLeftChildPtrstd::sharedptr leftPtr;
void setrightChildPtrstd::sharedptr rightPtr;
BinaryNodeTree Methods:
protected:
int getHeightHelperstd::sharedptr subTreePtr const;
int getNumberOfNodesHelperstd::sharedptr subTreePtr const;
auto balancedAddstd::sharedptr subTreePtr, std::sharedptr newNodePtr;
virtual auto removeValuestd::sharedptr subTreePtr, const ItemType target, bool& isSuccessful;
auto moveValuesUpTreestd::sharedptr subTreePtr;
virtual auto findNodestd::sharedptr subTreePtr, const ItemType& target, bool& isSuccessful const;
auto copyTreeconst std::sharedptr oldTreeRootPtr const;
void destroyTreestd::sharedptr subTreePtr;
void preordervoid visitItemType& std::sharedptr treePtr const;
void inordervoid visitItemType& std::sharedptr treePtr const;
void postordervoid visitItemType& std::sharedptr treePtr const;
public:
BinaryNodeTree;
BinaryNodeTreeconst ItemType& rootItem, const std::sharedptr leftTreePtr, const std::sharedptr rightTreePtr;
BinaryNodeTreeconst std::sharedptr& tree;
virtual ~BinaryNodeTree;
bool isEmpty const;
int getHeight const;
int getNumberOfNodes const;
ItemType getRootData const throwPrecondViolatedExcept;
void setRootDataconst ItemType& newData;
bool addconst ItemType& newData;
bool removeconst ItemType& data;
void clear;
ItemType getEntryconst ItemType& anEntry const thrownotFoundException;
bool containsconst ItemType& anEntry const;
void preorderTraversevoid visitItemType& const;
void inorderTraversevoid visitItemType& const;
void postorderTraversevoid visitItemType& const;
BinaryNodeTree& operatorconst BinaryNodeTree& rightHandSide;
BinarySearchTree methods:
protected:
auto placeNodestd::sharedptr subTreePtr, std::sharedptr newNode;
auto removeValuestd::sharedptr subTreePtr, const ItemType target, bool& isSuccessful override;
auto removeNodestd::sharedptr nodePtr;
auto removeLeftMostNodestd::sharedptrsubTreePtr, ItemType& inorderSuccessor;
auto findNodestd::sharedptr treePtr, const ItemType& target;
public:
BinarySearchTree;
BinarySearchTreeconst ItemType& rootItem;
BinarySearchTreeconst BinarySearchTree& tree;
virtual ~BinarySearchTree;
bool isEmpty;
int getHeight const;
int getNumberOfNodes const;
ItemType getRootData const throwPrecondViolatedExcept;
void setRootDataconst ItemType& newData;
bool addconst ItemType& newEntry;
bool removeconst ItemType& target;
void clear;
ItemType getEntryconst ItemType& anEntry const thrownotFoundException;
bool containsconst ItemType& anEntry const;
void preorderTraversevoid visitItemType& const;
void inorderTraversevoid visitItemType& const;
void p
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
