Ejemplo n.º 1
0
// Creates a new random-order dfs structure.
func New(g *graph.Graph, src int) *Dfs {
	d := new(Dfs)

	d.graph = g
	d.source = src

	d.visited = make([]bool, g.Vertices())
	d.parents = make([]int, g.Vertices())
	d.order = make([]int, 0, g.Vertices())

	d.pending = stack.New()
	d.pending.Push(src)
	d.builder = stack.New()

	return d
}
Ejemplo n.º 2
0
// Creates a new random-order bfs structure.
func New(g *graph.Graph, src int) *Bfs {
	d := new(Bfs)

	d.graph = g
	d.source = src

	d.visited = make([]bool, g.Vertices())
	d.visited[src] = true
	d.parents = make([]int, g.Vertices())
	d.order = make([]int, 1, g.Vertices())
	d.order[0] = src
	d.paths = make(map[int][]int)

	d.pending = queue.New()
	d.pending.Push(src)
	d.builder = stack.New()

	return d
}