22. Write a function to find the depth of a binary tree.
译:写个程序找到一个二叉树的深度。
struct Node
{
T data;
Node * left, * right;
};
int depth (Node * pNode)
{
return (pNode == NULL) ?
0 :
1 + max (depth (pNode->left), depth (pNode->right));
}
22. Write a function to find the depth of a binary tree.
译:写个程序找到一个二叉树的深度。
struct Node
{
T data;
Node * left, * right;
};
int depth (Node * pNode)
{
return (pNode == NULL) ?
0 :
1 + max (depth (pNode->left), depth (pNode->right));
}