howarezhao 发表于 2007-12-28 22:09

关于用二叉树实现非递归中序遍历出现的异常(JAVA语言的)

class Student{
    String name;                                    ;学生类
    int    score;
    Student llink;
    Student rlink;         
}
public void zhongxu(Student node){
        int i=1;                                  利用非递归的中序算法。
        Student stack[]=new Student[100];
         while(i>=1){
         while(node!=null){                     ;当node!=null时把二叉树的左结点入栈,直到到达树的末尾。
            stack[i]=node;
            i++;
            node=node.llink;
            }
        
            if(i>=0){                                        ;首先出栈,然后转向结点的右结点,再转向上面的模块。
            i--;
            node=stack[i];
            System.out.println(node.name+" "+node.score);
            node=node.rlink;
            }
        
        }
        
    }
结果虽然能运行,却出现异常,希望老前辈指点一下迷津~
[attach]31693[/attach]

[[italic] 本帖最后由 howarezhao 于 2007-12-28 22:12 编辑 [/italic]]


页: [1]

编程论坛