fix bugs in java codes using JDK 1.8.0

pull/254/head
sjinzh 2 years ago
parent a5affe6113
commit bb84df27cf

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

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

Loading…
Cancel
Save