Node* findKthSmallNode(Node *pNode, int &Kth)
{
if (!pNode)
return NULL;
Node* pRetNode = NULL;
pRetNode = findKthSmallNode(pNode->left, Kth);
if (pRetNode != NULL)
return pRetNode;
Kth--;
if (Kth == 0)
return pNode;
pRetNode = findKthSmallNode(pNode->left, Kth);
if (pRetNode != NULL)
return pRetNode;
return NULL;
}
查找BST中Kth小的元素
最新推荐文章于 2020-10-10 19:02:35 发布