Question: #ifndef TREE_BINARYTREE_H #define TREE_BINARYTREE_H class BinaryTree; class Node { public: void preorderDump(); private: int m_data; }; class BinaryTree { public: BinaryTree(int rootData); class Iterator {
| #ifndef TREE_BINARYTREE_H | |
| #define TREE_BINARYTREE_H | |
| class BinaryTree; | |
| class Node { | |
| public: | |
| void preorderDump(); | |
| private: | |
| int m_data; | |
| }; | |
| class BinaryTree { | |
| public: | |
| BinaryTree(int rootData); | |
| class Iterator { | |
| public: | |
| Iterator(Node * node); | |
| bool operator!=(Iterator rhs); | |
| Iterator left(); | |
| Iterator right(); | |
| void insertLeft(int data); | |
| void insertRight(int data); | |
| private: | |
| // whatever you want to add | |
| }; | |
| Iterator root(); | |
| // prints the tree as preorder traversal | |
| void preorderDump(); | |
| }; | |
| #endif //TREE_BINARYTREE_H |
| #include | |
| #include "BinaryTree.h" | |
| int main() { | |
| BinaryTree tree(4); | |
| auto itr = tree.root(); | |
| itr.insertLeft(4); | |
| itr = itr.left(); | |
| itr.insertRight(5); | |
| tree.preorderDump(); | |
| } |
-
Implement all the class methods of BinaryTree and its iterator. You may add any private methods or members you wish.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
