Content-Length: 2658 | pFad | http://github.com/algorithm-visualizer/algorithm-visualizer/pull/769.patch
thub.com
From 60f5993315e3e8a4768fa5b9bfedaf725fb2527e Mon Sep 17 00:00:00 2001
From: Frank-Gallagher
Date: Fri, 21 Mar 2025 15:39:56 +0800
Subject: [PATCH] Add files via upload
---
bfs.txt | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100644 bfs.txt
diff --git a/bfs.txt b/bfs.txt
new file mode 100644
index 00000000..ab98ca8e
--- /dev/null
+++ b/bfs.txt
@@ -0,0 +1,72 @@
+// import visualization libraries {
+import org.algorithm_visualizer.*;
+import java.util.LinkedList;
+import java.util.Queue;
+// }
+
+class Main {
+ // 可视化组件
+ private GraphTracer graphTracer = new GraphTracer("BFS");
+ private LogTracer logTracer = new LogTracer("控制台");
+ private Array1DTracer visitedTracer = new Array1DTracer("访问状态");
+
+ // 图结构定义
+ private int[][] adjMatrix = {
+ {0,1,1,0,0},
+ {1,0,0,0,1},
+ {1,0,0,1,0},
+ {0,0,1,0,1},
+ {0,1,0,1,0}
+ };
+ private boolean[] visited = new boolean[5];
+
+ void bfs(int start) {
+ Queue queue = new LinkedList<>();
+ queue.add(start);
+ visited[start] = true;
+
+ // 初始节点可视化
+ graphTracer.visit(start);
+ visitedTracer.patch(start, 1);
+ Tracer.delay(1000);
+
+ while (!queue.isEmpty()) {
+ int current = queue.poll();
+
+ for (int neighbor=0; neighbor
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/algorithm-visualizer/algorithm-visualizer/pull/769.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy