mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-12 07:26:07 +00:00
Update the book based on the revised second edition (#1014)
* Revised the book * Update the book with the second revised edition * Revise base on the manuscript of the first edition
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
)
|
||||
|
||||
/* 广度优先遍历 BFS */
|
||||
/* 广度优先遍历 */
|
||||
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
func graphBFS(g *graphAdjList, startVet Vertex) []Vertex {
|
||||
// 顶点遍历序列
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestGraphBFS(t *testing.T) {
|
||||
fmt.Println("初始化后,图为:")
|
||||
graph.print()
|
||||
|
||||
/* 广度优先遍历 BFS */
|
||||
/* 广度优先遍历 */
|
||||
res := graphBFS(graph, vets[0])
|
||||
fmt.Println("广度优先遍历(BFS)顶点序列为:")
|
||||
PrintSlice(VetsToVals(res))
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
)
|
||||
|
||||
/* 深度优先遍历 DFS 辅助函数 */
|
||||
/* 深度优先遍历辅助函数 */
|
||||
func dfs(g *graphAdjList, visited map[Vertex]struct{}, res *[]Vertex, vet Vertex) {
|
||||
// append 操作会返回新的的引用,必须让原引用重新赋值为新slice的引用
|
||||
*res = append(*res, vet)
|
||||
@@ -23,7 +23,7 @@ func dfs(g *graphAdjList, visited map[Vertex]struct{}, res *[]Vertex, vet Vertex
|
||||
}
|
||||
}
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
/* 深度优先遍历 */
|
||||
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
func graphDFS(g *graphAdjList, startVet Vertex) []Vertex {
|
||||
// 顶点遍历序列
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestGraphDFS(t *testing.T) {
|
||||
fmt.Println("初始化后,图为:")
|
||||
graph.print()
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
/* 深度优先遍历 */
|
||||
res := graphDFS(graph, vets[0])
|
||||
fmt.Println("深度优先遍历(DFS)顶点序列为:")
|
||||
PrintSlice(VetsToVals(res))
|
||||
|
||||
Reference in New Issue
Block a user