I am doing a a question in the book that asks me to write constructor and copy-control members for a class that has following variables. Can someone gimme a scenario/example where this class is useful? possible some codes in main function? The part I got confused is that why it needs TreeNode* left and TreeNode* right. I cannot think of the use of them.
#include <iostream>
#include <string>
using namespace std;
class TreeNode
{
public:
//constructor
TreeNode(const string& s, const int& n, const TreeNode& lm, const TreeNode& rm):
value(s), count(n), left(new TreeNode(lm)), right(new TreeNode(rm)) {}
//copy-constructor
TreeNode(const TreeNode& m): value(m.value), count(m.count), left(new TreeNode(*m.left)), right(new TreeNode(*m.right)) {}
//assignment operator
TreeNode& operator=(const TreeNode& m)
{
value = m.value;
count = m.count;
*left = *m.left;
*right = *m.right;
return *this;
}
//destructor
~TreeNode()
{
delete left;
delete right;
}
private:
string value;
int count;
TreeNode *left;
TreeNode *right;
};
int main ()
{
return 0;
}