-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreeTest.java
More file actions
53 lines (40 loc) · 897 Bytes
/
BinaryTreeTest.java
File metadata and controls
53 lines (40 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class BinaryTreeTest{
public static void main(String[] args){
}
}
class BinaryTree<E>{
private Node<E> root = newNode();
BinaryTree(){
}
public void insert(Node<E> node, E element){
if(node != null){
if(node.element == null){
node.element = element;
}
insert(node.leftChild, element);
insert(node.rightChild, element);
}
}
public void Create(E[] data){
for(E element : data){
insert(root, element);
}
}
public Node<E> newNode(){
return new Node<E>(new Node<E>(), null, new Node<E>());
}
public Node<E> newNode(E element){
return new Node<E>(new Node<E>(), element, new Node<E>());
}
private static class Node<T>{
T element;
Node<T> leftChild;
Node<T> rightChild;
Node(){}
Node(Node<T> lChild, T element, Node<T> rChild){
this.element = element;
this.leftChild = lChild;
this.rightChild = rChild;
}
}
}