import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class BTree {
String data = null;
BTree rightChild = null;
BTree leftChild = null;
}

public class Tree {

static void preOrder(BTree root) {

if (root == null) {
return;
}
System.out.print(root.data);
preOrder(root.leftChild);
preOrder(root.rightChild);

}

static void inOrder(BTree root) {

if (root == null) {
return;
}
inOrder(root.leftChild);
System.out.print(root.data);
inOrder(root.rightChild);

}

static BTree createTree(BTree root) {
String c = null;
System.out.print("请输入一个字符型:");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
try {
c = strin.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (c.equals("#")) {
root = null;
} else {
root = new BTree();
root.data = c;
root.leftChild = new BTree();
root.rightChild = new BTree();
root.leftChild = createTree(root.leftChild);
root.rightChild = createTree(root.rightChild);
}
return root;

}

static BTree createTree() {
String c = null;
System.out.print("请输入一个字符型:");
BufferedReader strin = new BufferedReader(new InputStreamReader(
System.in));
try {
c = strin.readLine();
} catch (IOException e) {
e.printStackTrace();
}
BTree root = new BTree();
if (c.equals("#")) {
root = null;
} else {
root.data = c;
root.leftChild = createTree();
root.rightChild = createTree();
}
return root;

}

static BTree createTree(String str, int current) {

char c = str.charAt(current);

BTree root = new BTree();
if (c == '#') {
root = null;
} else {
root.data = String.valueOf(c);
root.leftChild = createTree(str, current * 2 + 1);
root.rightChild = createTree(str, current * 2 + 2);
}
return root;

}

static int depth(BTree root) {
int result=0;
int left=0;
int right=0;
if (root != null) {

if (root.leftChild != null){
left = depth(root.leftChild);}
if (root.rightChild != null){
right = depth(root.rightChild);}
if (left > right) {
result= left + 1;
} else {
result= right + 1;
}
}
return result;
}

public static void main(String args[]) throws IOException {

BTree root = null;
String str = "ABCD#####";
root = createTree(str, 0);
System.out.println("-------------------------");
preOrder(root);
System.out.println("\n-------------------------");
inOrder(root);
System.out.println("\n-------------------------");
System.out.print(depth(root));
}

}