# 二叉树

``````class Node {
public Object data;
public Node left;
public Node right;
}
``````

``````public class Main {
public static void main(String args[]) {
Node a = new Node(Integer.valueOf(1));
Node b = new Node(Integer.valueOf(2));
Node c = new Node(Integer.valueOf(3));
a.left = b;
a.right = c;
}
}

class Node {
public Object data;
public Node left;
public Node right;

public Node(Object d) {
this.data = d;
}
}
``````

``````class BinarySearchTree<t extends comparable<t>&gt; {
public Node root;

public boolean insert(T i) {
if (root == null) {
root = new Node(i);
return true;
}

Node current = root;
while (true) {
// 如果 i 比当前结点的值小
if (i.compareTo((T) current.data) &lt; 0) {
if (current.left != null) {
current = current.left;
} else {
current.left = new Node(i);
break;
}
} else {
if (current.right != null)
current = current.right;
else {
current.right = new Node(i);
break;
}
}
}
return true;
}
}
``````

1. 为BinarySearchTree这个类添加一个方法：
``````public boolean contains(T t);
``````

1. 以不同的顺序往BST中插入数字，然后在纸上画一下，看看BST会变成什么样？举个例子，如果以(3, 2, 1, 5, 4, 6)的顺序插入的话，就会变成这个样子：