Question
HERE IS BASE #ifndef TREE_HPP #define TREE_HPP #include #include Treenode.hpp using std::cout; // Tree class-template definition template class Tree { public: // insert node in
HERE IS BASE
#ifndef TREE_HPP #define TREE_HPP #include
#include "Treenode.hpp" using std::cout;
// Tree class-template definition template
// begin preorder traversal of Tree void preOrderTraversal() const { preOrderHelper(rootPtr); }
// begin inorder traversal of Tree void inOrderTraversal() const { inOrderHelper(rootPtr); }
// begin postorder traversal of Tree void postOrderTraversal() const { postOrderHelper(rootPtr); }
NODETYPE* getArrayInOrder(NODETYPE x[]) { int c = 0; // counter inOrderArrayHelper(rootPtr, x, c); return x;
}
// get the depth of the tree int getDepth() { int totalDepth{0}; int currentDepth{0};
determineDepth(rootPtr, &totalDepth, ¤tDepth); return totalDepth; }
int getCount() { int count = 0;
countHelper(rootPtr, count); // count up the entire array return count; }
// begin binary search TreeNode
// OPTIMIZE THE TREE // pre a tree // post the tree optimized void Optimize() {
}
private: TreeNode
// utility function called by insertNode; receives a pointer // to a pointer so that the function can modify pointer's value void insertNodeHelper( TreeNode
// utility function to perform preorder traversal of Tree void preOrderHelper(TreeNode
// utility function to perform inorder traversal of Tree void inOrderHelper(TreeNode
void countHelper(TreeNode
// utility function to perform postorder traversal of Tree void postOrderHelper(TreeNode // calculate the depth of the tree // void determineDepth(.....) { // // } // } // do a binary search on the Tree // pre: a binary tree and a value to search for // post:; the pointer to the value searched for TreeNode if (ptr == nullptr) // value not in tree { cout // test if found if (ptr->data == val) { cout data data) // less than walk left { cout data leftPtr, val); // recursivly walk left } else // walk right { cout data rightPtr, val); // recursivly walk left } } // recursively dertermine the depth of a tree // pre; Root Ptr, highest Deppth, current depth // post :: highest depth void determineDepth(TreeNode x++; // increase current depth if (x > y) // update total depth y = x; determineDepth(subRootPtr->leftPtr, &y, &x); // go left x = *currentDepth; // reset current depth determineDepth(subRootPtr->rightPtr, &y, &x); // go right *totalDepth = y; // update pointer value *currentDepth = x; // update pointer value } } void inOrderArrayHelper(TreeNode }; #endif // TREE_HPP
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started