コード例 #1
0
func NewDirecteDepthFirst(g unweighted.UnweightedGraph, s int) DirectedDepthFirst {
	df := DirectedDepthFirst{
		g,
		make([]bool, g.Vertices()),
		0,
	}
	df.search(s)
	return df
}
コード例 #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
}
コード例 #3
0
func NewDirectedDepthFirstWithCycleDetection(g unweighted.UnweightedGraph, s int) DirectedDepthFirst {

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

	cd.search(s)
	return cd.directedDepthFirst
}
コード例 #4
0
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
}