Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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
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