• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

完全二叉树的先根、中根、后根遍历


Recommended Posts

包演示;

公共类P45 {

//完全二叉树的先根、中根、后根遍历

静态void preOrder(int[] arr,int index){

if(index=arr.length)

返回;

System.out.print(arr[index]',');//先输出根节点

前序(arr,2 index 1);//左子树

前序(arr,2 index 2);//右子树

}

静态void inOrder(int[] arr,int index){

if(index=arr.length)

返回;

inOrder(arr,2 * index 1);//左子树

System.out.print(arr[index]',');//根节点

inOrder(arr,2 * index 2);//右子树

}

静态void afterOrder(int[] arr,int index){

if(index=arr.length)

返回;

afterOrder(arr,2 * index 1);//左子树

afterOrder(arr,2 * index 2);//右子树

System.out.print(arr[index]',');//根节点

}

公共静态void main(String[] args) {

int[] arr={78,56,34,43,34 };

preOrder(arr,0);

系统。出去。println();

inOrder(arr,0);

系统。出去。println();

afterOrder(arr,0);

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now