Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9347968

Browse files
committed
fix Aha-Algorithms chapter5
1 parent 9a36389 commit 9347968

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

‎Aha-Algorithms/chapter5/5.1 bfs.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/**
2-
* 图的遍历 bfs 实现
2+
* 图的遍历 bfs 广度优先搜索 实现
33
*/
44
"use strict";
55

66
const util = require('../../util.js');
77
const Queue = require('../chapter2/Queue.js');
88

9+
/**
10+
* 图的邻接矩阵表示
11+
* 第 i 行,第 j 列表示的就是顶点 i 到顶点 j 是否有边,1 表示有边,NAN 表示没边,0 表示自己到自己
12+
* @type {number[][]}
13+
*/
914
var map = [
1015
[0, 1, 1, NaN, 1],
1116
[1, 0, NaN, 1, NaN],
@@ -26,7 +31,7 @@ result.push(start + 1);
2631
book[start] = 1;
2732

2833
while (!queue.isEmpty()) {
29-
let cur = queue.first();
34+
let cur = queue.dequeue();
3035

3136
for (let i = 0; i < n; i++) {
3237
if (map[cur][i] === 1 && book[i] === 0) {
@@ -35,7 +40,6 @@ while (!queue.isEmpty()) {
3540
result.push(i + 1);
3641
}
3742
}
38-
queue.dequeue();
3943
}
4044

4145
console.log('访问顺序', result);

‎Aha-Algorithms/chapter5/5.1 dfs.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/**
2-
* 图的遍历 dfs 实现
2+
* 图的遍历 dfs 深度优先搜索 实现
33
*/
44
"use strict";
55

66
const util = require('../../util.js');
77

8+
/**
9+
* 图的邻接矩阵表示
10+
* @type {number[][]}
11+
*/
812
var map = [
913
[0, 1, 1, NaN, 1],
1014
[1, 0, NaN, 1, NaN],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /