mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08: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:
@ -7,7 +7,7 @@
|
||||
import graph_adjacency_list_target
|
||||
import utils
|
||||
|
||||
/* 广度优先遍历 BFS */
|
||||
/* 广度优先遍历 */
|
||||
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
func graphBFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {
|
||||
// 顶点遍历序列
|
||||
@ -48,7 +48,7 @@ enum GraphBFS {
|
||||
print("\n初始化后,图为")
|
||||
graph.print()
|
||||
|
||||
/* 广度优先遍历 BFS */
|
||||
/* 广度优先遍历 */
|
||||
let res = graphBFS(graph: graph, startVet: v[0])
|
||||
print("\n广度优先遍历(BFS)顶点序列为")
|
||||
print(Vertex.vetsToVals(vets: res))
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
import graph_adjacency_list_target
|
||||
import utils
|
||||
|
||||
/* 深度优先遍历 DFS 辅助函数 */
|
||||
/* 深度优先遍历辅助函数 */
|
||||
func dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {
|
||||
res.append(vet) // 记录访问顶点
|
||||
visited.insert(vet) // 标记该顶点已被访问
|
||||
@ -21,7 +21,7 @@ func dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], v
|
||||
}
|
||||
}
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
/* 深度优先遍历 */
|
||||
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
func graphDFS(graph: GraphAdjList, startVet: Vertex) -> [Vertex] {
|
||||
// 顶点遍历序列
|
||||
@ -46,7 +46,7 @@ enum GraphDFS {
|
||||
print("\n初始化后,图为")
|
||||
graph.print()
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
/* 深度优先遍历 */
|
||||
let res = graphDFS(graph: graph, startVet: v[0])
|
||||
print("\n深度优先遍历(DFS)顶点序列为")
|
||||
print(Vertex.vetsToVals(vets: res))
|
||||
|
||||
Reference in New Issue
Block a user