标签:完全 存储 java can osi complete root util ++
/**
* @Author WaleGarrett
* @Date 2020/9/5 8:20
*/
import java.util.Arrays;
import java.util.Scanner;
/**
* PAT-1043,1064,1066,1086,1089,1099,1098
* 7
* 8 6 5 7 10 8 11
*/
public class PAT_1064 {
static final int maxn=1003;
static int[] node;
static int[] tree;//存储二叉树
static int N;
static int position=0;
static void inOrder(int root){
if(root>N)
return;
inOrder(root<<1);
tree[root]=node[position++];
inOrder(root<<1|1);
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
N=n;
node=new int[n];
tree=new int[n+1];
int i=0;
while(n!=0){
node[i]=scanner.nextInt();
i++;
n--;
}
Arrays.sort(node);
inOrder(1);
for(i=1;i<N;i++){
System.out.print(tree[i]+" ");
}
System.out.println(tree[N]);
}
}
PAT-1064(Complete Binary Search Tree)JAVA实现
标签:完全 存储 java can osi complete root util ++
原文地址:https://www.cnblogs.com/GarrettWale/p/13617358.html