BinaryTreeNode* KthNode(BinaryTreeNode* pRoot,unsiigned int k)
{
if(pRoot==nullptr||k==0)
return nullptr;
return KthNodeCore(pRoot,k);
}
BinaryTreeNode* KthNodeCore(BinaryTreeNode* pRoot,unsigned int &k)
{
BinaryTreeNode* target=nullptr;
if(pRoot->m_nLeft!=nullptr;)
target=KthNodeCore(pRoot->m_pLeft,k);
if(target==nullptr)
{
if(k==1)
target=pRoot;
k--;
}
}
if(target=nullptr&&pRoot->m_pRight!=nullptr)
target=KthNodeCore(pRoot->m_pRight,k);
return target;
二叉搜索树的第k大节点
最新推荐文章于 2020-04-13 16:49:37 发布