hello-algo/codes/go/chapter_graph/graph_dfs_test.go
Reanon 327f385d32
feat(go/graph): add go code for graph_dfs/bfs (#372)
* feat(vertex): add a vertex pkg

* feat(graph): add graph_bfs in go

* feat(graph): add graph_dfs in go

* fix(graph): fix comment

* fix(graph): fix graph_adj_list

* fix(go/graph): fix graph_adjacency

* fix(c): gitignore

* feat(graph): print order adjList graph

* fix(graph): remove order print

* Update graph_adjacency_list_test.go

* Update .gitignore

* Update .gitignore

---------

Co-authored-by: Yudong Jin <krahets@163.com>
2023-02-27 20:34:30 +08:00

28 lines
682 B
Go
Raw 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_dfs_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 TestGraphDFS(t *testing.T) {
/* 初始化无向图 */
vets := ValsToVets([]int{0, 1, 2, 3, 4, 5, 6})
edges := [][]Vertex{
{vets[0], vets[1]}, {vets[0], vets[3]}, {vets[1], vets[2]},
{vets[2], vets[5]}, {vets[4], vets[5]}, {vets[5], vets[6]}}
graph := newGraphAdjList(edges)
fmt.Println("初始化后,图为:")
graph.print()
/* 深度优先遍历 DFS */
res := graphDFS(graph, vets[0])
fmt.Println("深度优先遍历DFS顶点序列为:")
PrintSlice(VetsToVals(res))
}