-
Notifications
You must be signed in to change notification settings - Fork 0
/
P46.java
34 lines (27 loc) · 805 Bytes
/
P46.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
package binarytree;
import java.util.NoSuchElementException;
public final class P46 {
private P46() {
}
/**
* Create balanced tree.
* cbal_tree(4,T)
* Insert all items into AVL (Binary balanced tree).
*
* @param countNodes number of nodes
* @param integers items
* @return avl tree (balanced tree)
*/
public static AVLTree createBalancedTree(Integer countNodes, Integer... integers) {
AVLTree tree = new AVLTree();
if (integers == null) {
return null;
}
if (countNodes <= 0 || integers.length <= 0) {
throw new NoSuchElementException("Nodes items is empty");
}
for (Integer i : integers)
tree.root = tree.insert(tree.root, i);
return tree;
}
}