-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBinaryTree.java
More file actions
52 lines (41 loc) · 1.11 KB
/
BinaryTree.java
File metadata and controls
52 lines (41 loc) · 1.11 KB
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
51
52
import java.util.LinkedList;
import java.util.Queue;
/**
* Created by Devang on 6/21/2017.
*/
public class BinaryTree<E> {
BNode<E> root;
Queue<BNode> myQ;
public BinaryTree() {
this.myQ = new LinkedList<>();
}
protected class BNode<E>{
protected E data;
protected BNode<E> left;
protected BNode<E> right;
protected BNode(E data) {
this.data = data;
}
}
public void insert(E data){
BNode newNode = new BNode(data);
if(this.root == null){
this.root = newNode;
} else {
BNode current = myQ.peek();
if(current.left == null){
current.left = new BNode(data);
} else if(current.right == null){
current.right = new BNode(data);
myQ.remove();
}
}
myQ.add(newNode);
}
public static void main(String[] args) {
int[] a = {1,2,3,4,5,6,7,8,9,10};
insertAll(a);
}
public static void insertAll(int[] list){
}
}