Ejemplo n.º 1
0
func (sp *DijkstraShortestPaths) PathTo(v int) []weighted.Edge {
	if !sp.HasPathTo(v) {
		return nil
	}

	path := collections.Stack{}

	for e := sp.edgeTo[v]; e.Initialized(); e = sp.edgeTo[e.From()] {
		path.Push(e)
	}

	return convert(path)
}
Ejemplo n.º 2
0
// Path from s to v
func (dfp *DepthFirstPaths) PathTo(v int) []int {
	if !dfp.HasPathTo(v) {
		return []int{}
	}
	path := collections.Stack{}
	for x := v; x != dfp.s; x = dfp.edgeTo[x] {
		path.Push(x)
	}
	path.Push(dfp.s)

	return path.ConvertToInt()
}