-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathBasicBTreeNodeSearchDemo.java
55 lines (40 loc) · 1.13 KB
/
BasicBTreeNodeSearchDemo.java
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
53
54
55
package ds_011_balanced_trees;
public class BasicBTreeNodeSearchDemo {
/*
* |11|25|-|-|
* / | \
* ______________/ | \______________
* | | |
* |2|5|-|-| |13|15|16|18| |32|37|-|-|
*/
public static void main(String[] args) {
DummyBTreeNode<Integer> root = prepareRoot();
System.out.println("Found: " + root.find(37));
root.printBucket();
}
private static DummyBTreeNode<Integer> prepareRoot() {
DummyBTreeNode<Integer> root = new DummyBTreeNode<>(2);
// level 0
root.add(11);
root.add(25);
// level 1
// child1
DummyBTreeNode<Integer> child1 = new DummyBTreeNode<>(2);
child1.add(2);
child1.add(5);
root.branches[0] = child1;
// child2
DummyBTreeNode<Integer> child2 = new DummyBTreeNode<>(2);
child2.add(13);
child2.add(15);
child2.add(16);
child2.add(18);
root.branches[1] = child2;
// child3
DummyBTreeNode<Integer> child3 = new DummyBTreeNode<>(2);
child3.add(32);
child3.add(37);
root.branches[2] = child3;
return root;
}
}