Example #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
}
Example #2
0
// Simple usage example that inserts the numbers 1, 2, 3 into a stack and then
// removes them one by one, printing them to the standard output.
func Example_usage() {
	// Create a stack and push some data in
	s := stack.New()
	for i := 0; i < 3; i++ {
		s.Push(i)
	}
	// Pop out the stack contents and display them
	for !s.Empty() {
		fmt.Println(s.Pop())
	}
	// Output:
	// 2
	// 1
	// 0
}
Example #3
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
}