Пример #1
0
func Search(g graph.Graph, source int) DFS {
	dfs := &dfs{
		graph:  g,
		marked: make([]bool, g.Vertices()),
	}
	dfs.search(source)
	return dfs
}
Пример #2
0
import (
	. "github.com/jmnarloch/gograph/bfs"

	"github.com/jmnarloch/gograph/digraph"
	"github.com/jmnarloch/gograph/graph"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Bread first search", func() {

	vertices := 10

	Context("Undirected graph", func() {

		var g graph.Graph
		var bfs BFS

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

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

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