类 Cycle
- java.lang.Object
-
- edu.princeton.cs.algs4.Cycle
-
public class Cycle extends java.lang.Object
TheCycle
class represents a data type for determining whether an undirected graph has a simple cycle. The hasCycle operation determines whether the graph has a 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.
For additional documentation, see Section 4.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器详细资料
-
Cycle
public Cycle(Graph G)
Determines whether the undirected graphG
has a cycle and, if so, finds such a cycle.- 参数:
G
- the undirected graph
-
-
方法详细资料
-
hasCycle
public boolean hasCycle()
Returns true if the graphG
has a cycle.- 返回:
true
if the graph has a cycle;false
otherwise
-
cycle
public java.lang.Iterable<java.lang.Integer> cycle()
Returns a cycle in the graphG
.- 返回:
- a cycle if the graph
G
has a cycle, andnull
otherwise
-
main
public static void main(java.lang.String[] args)
Unit tests theCycle
data type.- 参数:
args
- the command-line arguments
-
-