hello-algo/codes/go/chapter_graph/graph_bfs_test.go
Yudong Jin f68bbb0d59
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
2023-12-28 18:06:09 +08:00

29 lines
809 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// File: graph_bfs_test.go
// Created Time: 2023-02-18
// Author: Reanon (793584285@qq.com)
package chapter_graph
import (
"fmt"
"testing"
. "github.com/krahets/hello-algo/pkg"
)
func TestGraphBFS(t *testing.T) {
/* 初始化无向图 */
vets := ValsToVets([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
edges := [][]Vertex{
{vets[0], vets[1]}, {vets[0], vets[3]}, {vets[1], vets[2]}, {vets[1], vets[4]},
{vets[2], vets[5]}, {vets[3], vets[4]}, {vets[3], vets[6]}, {vets[4], vets[5]},
{vets[4], vets[7]}, {vets[5], vets[8]}, {vets[6], vets[7]}, {vets[7], vets[8]}}
graph := newGraphAdjList(edges)
fmt.Println("初始化后,图为:")
graph.print()
/* 广度优先遍历 */
res := graphBFS(graph, vets[0])
fmt.Println("广度优先遍历BFS顶点序列为:")
PrintSlice(VetsToVals(res))
}