Пример #1
0
func DirectedSearch(g digraph.Digraph, sources ...int) DFS {
	dfs := &dfs{
		graph:  g,
		marked: make([]bool, g.Vertices()),
	}
	for _, source := range sources {
		dfs.search(source)
	}
	return dfs
}
Пример #2
0
		It("should perform bread first search", func() {

			Expect(bfs).NotTo(BeNil())
		})

		It("should verify that every node is connected", func() {

			for ind := 0; ind < vertices; ind++ {
				Expect(bfs.Marked(ind)).To(BeTrue())
			}
		})
	})

	Context("Directed graph", func() {

		var g digraph.Digraph
		var bfs BFS

		BeforeEach(func() {
			g = digraph.New(vertices)
			for ind := 0; ind < vertices-1; ind++ {
				g.AddEdge(ind, ind+1)
			}
			bfs = DirectedSearch(g, 0)
		})

		It("should perform bread first search", func() {

			Expect(bfs).NotTo(BeNil())
		})