Anonymous inner classes create generic instances that display the dec… (#627)

* Anonymous inner classes create generic instances that display the declared type

* Update TreeNode.java

* Update binary_tree_bfs.java

* Update graph_bfs.java

---------

Co-authored-by: zongjianwei <zongjianwei@meituan.com>
Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
ZongYangL
2023-07-19 01:37:55 +08:00
committed by GitHub
parent 7a6fd4b3dd
commit 03cbf5b972
3 changed files with 9 additions and 5 deletions

View File

@@ -16,9 +16,11 @@ public class graph_bfs {
// 顶点遍历序列
List<Vertex> res = new ArrayList<>();
// 哈希表,用于记录已被访问过的顶点
Set<Vertex> visited = new HashSet<>() {{ add(startVet); }};
Set<Vertex> visited = new HashSet<>();
visited.add(startVet);
// 队列用于实现 BFS
Queue<Vertex> que = new LinkedList<>() {{ offer(startVet); }};
Queue<Vertex> que = new LinkedList<>();
que.offer(startVet);
// 以顶点 vet 为起点,循环直至访问完所有顶点
while (!que.isEmpty()) {
Vertex vet = que.poll(); // 队首顶点出队