1 public BiTNode createBiTree(BiTNode parent_node) 2 { 3 Scanner input = new Scanner(System.in); 4 int k = input.nextInt(); 5 if(k == -1) 6 return null; 7 8 BiTNode node = new BiTNode(k); 9 node.parent = parent_node; //保证根结点的parent为null 10 node.lchild = createBiTree(node); 11 node.rchild = createBiTree(node); 12 return node; 13 } 14 15 public static void main(String[] args) 16 { 17 BiTree tree = new BiTree(); 18 tree.root = tree.createBiTree(null); 19 }