平衡二叉树中序遍历(有序)
二叉搜索树的第k个结点
http://www.nowcoder.com/questionTerminal/ef068f602dde4d28aab2b210e859150a
二叉平衡树中序遍历是有序的。
只需要中序遍历就好了
class Solution {
public:
int index;
TreeNode* root=NULL;
TreeNode* KthNode(TreeNode* pRoot, int k)
{
//中序遍历,第k个
index=k;
inOrder(pRoot);
return root;
}
void inOrder(TreeNode *pRoot)
{
if(pRoot==NULL)
return ;
inOrder(pRoot->left);
index--;
if(index==0){
root=pRoot;
return ;
}
inOrder(pRoot->right);
}
};
