类 EdgeWeightedDirectedCycle
- java.lang.Object
-
- edu.princeton.cs.algs4.EdgeWeightedDirectedCycle
-
public class EdgeWeightedDirectedCycle extends java.lang.Object
TheEdgeWeightedDirectedCycle
class represents a data type for determining whether an edge-weighted digraph has a directed cycle. The hasCycle operation determines whether the edge-weighted digraph has a directed cycle and, if so, the cycle operation returns one.This implementation uses depth-first search. The constructor takes time proportional to V + E (in the worst case), where V is the number of vertices and E is the number of edges. Afterwards, the hasCycle operation takes constant time; the cycle operation takes time proportional to the length of the cycle.
See
Topological
to compute a topological order if the edge-weighted digraph is acyclic.For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 EdgeWeightedDirectedCycle(EdgeWeightedDigraph G)
Determines whether the edge-weighted digraphG
has a directed cycle and, if so, finds such a cycle.
-
方法概要
修饰符和类型 方法 说明 java.lang.Iterable<DirectedEdge>
cycle()
Returns a directed cycle if the edge-weighted digraph has a directed cycle, andnull
otherwise.boolean
hasCycle()
Does the edge-weighted digraph have a directed cycle?static void
main(java.lang.String[] args)
Unit tests theEdgeWeightedDirectedCycle
data type.
-
-
-
构造器详细资料
-
EdgeWeightedDirectedCycle
public EdgeWeightedDirectedCycle(EdgeWeightedDigraph G)
Determines whether the edge-weighted digraphG
has a directed cycle and, if so, finds such a cycle.- 参数:
G
- the edge-weighted digraph
-
-
方法详细资料
-
hasCycle
public boolean hasCycle()
Does the edge-weighted digraph have a directed cycle?- 返回:
true
if the edge-weighted digraph has a directed cycle,false
otherwise
-
cycle
public java.lang.Iterable<DirectedEdge> cycle()
Returns a directed cycle if the edge-weighted digraph has a directed cycle, andnull
otherwise.- 返回:
- a directed cycle (as an iterable) if the edge-weighted digraph
has a directed cycle, and
null
otherwise
-
main
public static void main(java.lang.String[] args)
Unit tests theEdgeWeightedDirectedCycle
data type.- 参数:
args
- the command-line arguments
-
-