递归实现树的遍历

来源:互联网 发布:银河系 知乎 编辑:程序博客网 时间:2024/05/16 00:49

1 void preOrderPrint() {

system.out.print( value.toString() + " ");

if (left != nulll) {

left.preOrderPrint();

}

if (right != null) {

right.preOrderPrint();

}

}


2 void inOrderPrint() {

if(left != null) {

left.inOrderPrint();

}

system.out.print(value.toString() + " ");

if(right != null) {

right.inOrderPrint();

}

}


3 void postOrderPrint() {

if (left != null) {

left.postOrderPrint();

}

if(right != null) {

right.postOrderPrint();

}

system.out.print(value.toString() + " ");

}

0 0
原创粉丝点击