forked from algorithm016-algorithm016/algorithm016
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralUtils.java
More file actions
45 lines (32 loc) · 1.16 KB
/
GeneralUtils.java
File metadata and controls
45 lines (32 loc) · 1.16 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
package src.utils;
import src.common.node.TreeNode;
import src.common.tree.BinarySearchTree;
import src.common.tree.FullBinaryTree;
import src.common.node.TreeNodeWithParent;
import src.common.tree.NormalBinaryTree;
import java.util.Deque;
import java.util.LinkedList;
public class GeneralUtils {
//[5,4,6,null,null,3,7]
public static TreeNode constructNormalBinaryTree(Integer[] nums){
return new NormalBinaryTree().createTreeByRecursion(nums);
}
public static TreeNode constructBinarySearchTree(Integer[] nums){
return new BinarySearchTree().createTreeByRecursion(nums);
}
/**
* 生成 几层满二叉树
* @param level
* @return
*/
public static TreeNodeWithParent<Integer> constructFullBinaryNode(int level){
TreeNodeWithParent<Integer> rootNode = FullBinaryTree.genBinaryTree(level);
return rootNode;
}
public static void main(String[] args) {
// Integer[] arr = new Integer[]{5,4,6,null,null,3,7};
// printTreeNode(constructTree(arr));
TreeNodeWithParent<Integer> node = constructFullBinaryNode(10);
PrintTreeUtils.printTreeNode(node);
}
}