33,008
社区成员
发帖
与我相关
我的任务
分享
void secondDepth(node* root,int depth,int& secondDepth, int maxDepth)
{
if(root->lchild==null && root->rchild==null)
{
depth ++;
if(depth > maxDepth)
{
secondDepth = maxDepth ;
maxDepth = depth;
} else if(depth > secondDepth && depth!=maxDepth)
{
secondDepth = depth;
}
return ;
}
if(root->lchild)
secondDepth( root->lchild,depth+1,secondDepth,maxDepth);
if(root->rchild)
secondDepth( root->rchild,depth+1,secondDepth,maxDepth);
}
void secondDepth(node* root,int depth,int& secondDepth, int maxDepth)
{
if(root->lchild==null && root->rchild==null)
{
depth ++;
if(depth > maxDepth)
{
secondDepth = maxDepth ;
maxDepth = depth;
} else if(depth > secondDepth)
{
secondDepth = depth;
}
return ;
}
if(root->lchild)
secondDepth( root->lchild,depth+1,secondDepth,maxDepth);
if(root->rchild)
secondDepth( root->rchild,depth+1,secondDepth,maxDepth);
}