struct Node { Node(int value) { _value = value; _left = NULL; _right = NULL; } Node* _left; int _value; Node* _right; }; int MaxDepth(const Node* root) { if(root == NULL) return 0; int iLeftDepth = MaxDepth(root->_left); int iRightDepth = MaxDepth(root->_right); return (iLeftDepth > iRightDepth) ? (iLeftDepth + 1) : (iRightDepth + 1); }
No comments:
Post a Comment