I was doing exercises in a website and in exercise we must find height of a non-binary tree by implementing a function. I have a TreeNode class in below.
class TreeNode
{
public:
TreeNode();
TreeNode(string data);
void addChild(TreeNode* child);
vector<TreeNode*>& getChildren();
void setData(string data);
string getData();
void visit();
};
I implement this http://codepad.org/BiXkbABf. But this doesn’t work. How can I implement this function?
return 1 + maxi; is an error. you already accounting for the current node ink = 1 + max(height((tree->getChildren)()[i]),height((tree->getChildren)()[i+1]));