package Tree;
public class Test {
public static void main(String[] args) {
int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
Tree t=new Tree(arr);
t.order();
}
}
class Tree{
private int[] arr;
//初始化
public Tree (int[] arr){
this.arr=arr;
}
//重载
public void order(){
this.order(0);
}
//前序
public void order(int index){
if (arr==null || arr.length==0){
System.out.println("遍历");
}
System.out.println(arr[index]);
//左递归
if (2*index+1 <arr.length){
order(2*index+1);
}
//右递归
if (2*index+2 <arr.length){
order(2*index+2);
}
}
}