1.首先构造树结构
struct TreeNode
{
int _value;
TreeNode* _pre;
TreeNode* _pnext;
TreeNode(int value, TreeNode* pre = nullptr, TreeNode* pnext = nullptr)
:_value(value), _pre(pre), _pnext(pnext) {};
};
2.使用递归的方法遍历得到最大深度值:
class TreeHeight
{
int getHeight(TreeNode* root)
{
if (root)
{
int hl = getHeight(root->_pre);
int hr = getHeight(root->_pnext);
int h = hl > hr ? hl : hr;
return h + 1;
}
return 0;
}
}