add zig codes for Section 'Heap' (heap.zig)

pull/256/head
sjinzh 2 years ago
parent 5bda3dd91f
commit bf907e1715

@ -13,7 +13,7 @@ public class binary_tree_bfs {
/* 层序遍历 */ /* 层序遍历 */
static List<Integer> hierOrder(TreeNode root) { static List<Integer> hierOrder(TreeNode root) {
// 初始化队列,加入根结点 // 初始化队列,加入根结点
Queue<TreeNode> queue = new LinkedList<TreeNode>() {{ add(root); }}; Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
// 初始化一个列表,用于保存遍历序列 // 初始化一个列表,用于保存遍历序列
List<Integer> list = new ArrayList<>(); List<Integer> list = new ArrayList<>();
while (!queue.isEmpty()) { while (!queue.isEmpty()) {

@ -32,7 +32,7 @@ public class TreeNode {
return null; return null;
TreeNode root = new TreeNode(list.get(0)); TreeNode root = new TreeNode(list.get(0));
Queue<TreeNode> queue = new LinkedList<TreeNode>() {{ add(root); }}; Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
int i = 0; int i = 0;
while(!queue.isEmpty()) { while(!queue.isEmpty()) {
TreeNode node = queue.poll(); TreeNode node = queue.poll();
@ -58,7 +58,7 @@ public class TreeNode {
public static List<Integer> treeToList(TreeNode root) { public static List<Integer> treeToList(TreeNode root) {
List<Integer> list = new ArrayList<>(); List<Integer> list = new ArrayList<>();
if(root == null) return list; if(root == null) return list;
Queue<TreeNode> queue = new LinkedList<TreeNode>() {{ add(root); }}; Queue<TreeNode> queue = new LinkedList<>() {{ add(root); }};
while(!queue.isEmpty()) { while(!queue.isEmpty()) {
TreeNode node = queue.poll(); TreeNode node = queue.poll();
if(node != null) { if(node != null) {

Loading…
Cancel
Save