中序遍历二叉查找树,就是一个从小到大的顺序,每次记录节点个数
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
private int cnt=0;
private TreeNode ret;
TreeNode KthNode(TreeNode pRoot, int k)
{
inOrder(pRoot,k);
return ret;
}
private void inOrder(TreeNode root,int k){
if(root==null||cnt>=k){
return;
}
inOrder(root.left,k);
cnt++;
if(cnt==k){
ret=root;
}
inOrder(root.right,k);
}
}
前序,中序,后序,层次遍历二叉树的递归和非递归方法,非递归就是用栈。
https://blog.csdn.net/coder__666/article/details/80349039