Skip to content

Commit a1a239d

Browse files
committed
Add comments and fixes issue
1 parent babff99 commit a1a239d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/graphs/searching/bfs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ var breadthFirstSearch = (function () {
4040
}
4141
}
4242

43+
/**
44+
* Process given node
45+
*
46+
* @param {number} destination The destionation, which should be reached
47+
* @param {number} current The current node
48+
* @param {number} node Neighbour node
49+
*/
4350
function processNode(destination, current, node) {
4451
if (graph[current][node]) {
4552
if (node === destination) {
@@ -70,7 +77,10 @@ var breadthFirstSearch = (function () {
7077
current = queue.shift();
7178
visited[current] = true;
7279
for (var i = 0; i < graph.length; i += 1) {
73-
processNode(destination, current, i);
80+
var result = processNode(destination, current, i);
81+
if (result) {
82+
return true;
83+
}
7484
}
7585
}
7686
return false;

0 commit comments

Comments
 (0)