From 3962826c2dd12df821fd8678afe4e65de3b2f39a Mon Sep 17 00:00:00 2001 From: Wizard-F Date: Mon, 18 Apr 2022 00:09:57 +0800 Subject: [PATCH] Restructure BFS/tree.js --- Brute Force/Breadth-First Search/tree.js | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Brute Force/Breadth-First Search/tree.js b/Brute Force/Breadth-First Search/tree.js index f2c8411b..15eeec40 100644 --- a/Brute Force/Breadth-First Search/tree.js +++ b/Brute Force/Breadth-First Search/tree.js @@ -16,17 +16,24 @@ const G = [ // G[i][j] indicates whether the path from the i-th node to the j-th [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]; -// define tracer variables { -const tracer = new GraphTracer(); -const logger = new LogTracer(); -tracer.log(logger); -Layout.setRoot(new VerticalLayout([tracer, logger])); -tracer.set(G); -tracer.layoutTree(0); -Tracer.delay(); -// } +/** + * Traverse a tree in breadth-first order. + * + * @param G The tree to be traversed, represented by an adjacency matrix. + * @param s The starting node. + */ +function BFS(G, s) { + + // define tracer variables { + const tracer = new GraphTracer(); + const logger = new LogTracer(); + tracer.log(logger); + Layout.setRoot(new VerticalLayout([tracer, logger])); + tracer.set(G); + tracer.layoutTree(0); + Tracer.delay(); + // } -function BFS(s) { // s = start node const Q = []; Q.push(s); // add start node to queue // visualize { @@ -47,4 +54,4 @@ function BFS(s) { // s = start node } } -BFS(0); +BFS(G, 0); \ No newline at end of file