Question: c++ programming homework // goddard - TreeNode.h - 2020 #ifndef TREENODE_H #define TREENODE_H #include using namespace std; class TreeNode { private: const string value; //

 c++ programming homework c++ programming homework // goddard - TreeNode.h - 2020 #ifndef TREENODE_H // goddard - TreeNode.h - 2020 #ifndef TREENODE_H #define TREENODE_H #include using namespace std; class TreeNode { private: const string value; // contains node value TreeNode * lchild; // reference to node's left child TreeNode * rchild; // reference to node's right child public: TreeNode (string str) : value(str) , lchild(nullptr) , rchild(nullptr) { } void setLeft( TreeNode* l) { lchild = l; } void setRight( TreeNode* r) { rchild = r; } void postorder ( ) const ; void preorder( ) const; }; #endif

// goddard - TreeDriver.cpp - 2020 // a rather poor tester for TreeNode #include using namespace std; #include "TreeNode.h" int main() { // Create tree by hand here. TreeNode * t1 = new TreeNode("A"); TreeNode * t2 = new TreeNode("B"); TreeNode * t3 = new TreeNode("C"); TreeNode * t4 = new TreeNode("D"); TreeNode * t5 = new TreeNode("E"); TreeNode * t6 = new TreeNode("F"); TreeNode * t7 = new TreeNode("G"); t1->setLeft(t2); t1->setRight(t3); t2->setLeft(t4); t2->setRight(t5); t3->setLeft(t6); t3->setRight(t7); cout postorder( ); cout preorder( ); delete t1; delete t2; delete t3; delete t4; delete t5; delete t6; delete t7; return 0; } 

Objective You are given a header file for class TreeNode (which should not be altered). Your task is to implement the two traversals: void postorder () should print out the tree in postorder (assuming that node is the root). This method should use recursion. void preorder () should print out the tree in preorder (assuming that node is the root). This method must use a single stack from the STL, but neither recursion nor any other data structure. The provided driver does some limited testing. Adapt as desired. Handin only TreeNode.cpp Objective You are given a header file for class TreeNode (which should not be altered). Your task is to implement the two traversals: void postorder () should print out the tree in postorder (assuming that node is the root). This method should use recursion. void preorder () should print out the tree in preorder (assuming that node is the root). This method must use a single stack from the STL, but neither recursion nor any other data structure. The provided driver does some limited testing. Adapt as desired. Handin only TreeNode.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!