您的当前位置:首页正文

Tree:给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下

来源:华佗小知识
public TreeLinkNode GetNext(TreeLinkNode pNode) {
        if (pNode==null) {
            return null;
        }
        if (pNode.right!=null) {
            return getMostLeft(pNode.right);
        }
        TreeLinkNode parent = pNode.next;
        while (parent!=null&&parent.left!=pNode) {
            pNode = parent;
            parent = parent.next;
        }
        return parent;
    }
    public TreeLinkNode getMostLeft(TreeLinkNode node) {
        while (node.left!=null) {
            node = node.left;
        }
        return node;
    }