c++
二叉搜索树的第k个结点
http://www.nowcoder.com/questionTerminal/ef068f602dde4d28aab2b210e859150a
class Solution {
public:
TreeNode* KthNode(TreeNode* pRoot, int k)
{
if (pRoot == NULL || k == 0) return NULL;
stack<TreeNode*> st;
TreeNode* p = pRoot;
while(!st.empty() || p) {
while(p) {
st.push(p);
p = p->left;
}
TreeNode* t = st.top();
st.pop();
k--;
if (k == 0) return t;
p = t->right;
}
return NULL;
}
};
