func NewDirecteDepthFirst(g unweighted.UnweightedGraph, s int) DirectedDepthFirst {
	df := DirectedDepthFirst{
		g,
		make([]bool, g.Vertices()),
		0,
	}
	df.search(s)
	return df
}
Beispiel #2
0
func NewDepthFirstPaths(g unweighted.UnweightedGraph, s int) DepthFirstPaths {
	dfp := DepthFirstPaths{
		g:      g,
		marked: make([]bool, g.Vertices()),
		edgeTo: make([]int, g.Vertices()),
		s:      s,
		count:  0,
	}
	dfp.search(s)
	return dfp
}
func NewDirectedDepthFirstWithCycleDetection(g unweighted.UnweightedGraph, s int) DirectedDepthFirst {

	cd := DirectedDepthFirstWithCycleDetection{directedDepthFirst: DirectedDepthFirst{
		g,
		make([]bool, g.Vertices()),
		0,
	}}

	cd.search(s)
	return cd.directedDepthFirst
}
func NewConnectedComponents(g unweighted.UnweightedGraph) ConnectedComponents {
	cc := ConnectedComponents{g, make([]bool, g.Vertices()), make([]int, g.Vertices()), 0}

	for s := 0; s < cc.g.Vertices(); s++ {
		if !cc.marked[s] {
			cc.search(s)
			cc.count++
		}
	}

	return cc
}