diff --git a/codes/java/chapter_tree/binary_tree_bfs.java b/codes/java/chapter_tree/binary_tree_bfs.java index 81895dd4a..ffeb352e0 100644 --- a/codes/java/chapter_tree/binary_tree_bfs.java +++ b/codes/java/chapter_tree/binary_tree_bfs.java @@ -13,7 +13,7 @@ public class binary_tree_bfs { /* 层序遍历 */ static List hierOrder(TreeNode root) { // 初始化队列,加入根结点 - Queue queue = new LinkedList() {{ add(root); }}; + Queue queue = new LinkedList<>() {{ add(root); }}; // 初始化一个列表,用于保存遍历序列 List list = new ArrayList<>(); while (!queue.isEmpty()) { diff --git a/codes/java/include/TreeNode.java b/codes/java/include/TreeNode.java index 5a87e8a7b..22a349747 100644 --- a/codes/java/include/TreeNode.java +++ b/codes/java/include/TreeNode.java @@ -32,7 +32,7 @@ public class TreeNode { return null; TreeNode root = new TreeNode(list.get(0)); - Queue queue = new LinkedList() {{ add(root); }}; + Queue queue = new LinkedList<>() {{ add(root); }}; int i = 0; while(!queue.isEmpty()) { TreeNode node = queue.poll(); @@ -58,7 +58,7 @@ public class TreeNode { public static List treeToList(TreeNode root) { List list = new ArrayList<>(); if(root == null) return list; - Queue queue = new LinkedList() {{ add(root); }}; + Queue queue = new LinkedList<>() {{ add(root); }}; while(!queue.isEmpty()) { TreeNode node = queue.poll(); if(node != null) {