相关疑难解决方法(0)

使用Stack的二叉搜索树的Inorder Tree Traversal算法

我的输入结果24, 4, 2, 3, 9, 10, 32,我得到了以下结果2, 3, 4, 24.

我正在使用堆栈.当我手动检查这个程序时else if,即使有正确的子树,节点也不会在堆栈上的4处进行.

public void inorderNonRcursive(Node root){

    Stack s = new Stack();
    Node node = root;
    Node k;
    int c=0;

    if(node != null) {
        s.push(node);    
    }

    while(!s.stack.isEmpty()) {   

        //node=(Node) s.stack.get(s.stack.size()-1);
        System.out.println("first condition" + (node.getleft() != null && (node.getVisited() == false)) + "second condi" + (node.getRight() != null));

        if(node.getleft() != null && (node.getVisited() == false)) {
            node = node.getleft();
            s.push(node);
            System.out.println("   from 1           "+(++c)); …
Run Code Online (Sandbox Code Playgroud)

java stack inorder binary-search-tree

1
推荐指数
1
解决办法
4775
查看次数

标签 统计

binary-search-tree ×1

inorder ×1

java ×1

stack ×1