类 CC
- java.lang.Object
-
- edu.princeton.cs.algs4.CC
-
public class CC extends java.lang.Object
TheCC
class represents a data type for determining the connected components in an undirected graph. The id operation determines in which connected component a given vertex lies; the connected operation determines whether two vertices are in the same connected component; the count operation determines the number of connected components; and the size operation determines the number of vertices in the connect component containing a given vertex. The component identifier of a connected component is one of the vertices in the connected component: two vertices have the same component identifier if and only if they are in the same connected component.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 id, count, connected, and size operations take constant time.
For additional documentation, see Section 4.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 CC(EdgeWeightedGraph G)
Computes the connected components of the edge-weighted graphG
.CC(Graph G)
Computes the connected components of the undirected graphG
.
-
方法概要
修饰符和类型 方法 说明 boolean
areConnected(int v, int w)
已过时。Replaced byconnected(int, int)
.boolean
connected(int v, int w)
Returns true if verticesv
andw
are in the same connected component.int
count()
Returns the number of connected components in the graphG
.int
id(int v)
Returns the component id of the connected component containing vertexv
.static void
main(java.lang.String[] args)
Unit tests theCC
data type.int
size(int v)
Returns the number of vertices in the connected component containing vertexv
.
-
-
-
构造器详细资料
-
CC
public CC(Graph G)
Computes the connected components of the undirected graphG
.- 参数:
G
- the undirected graph
-
CC
public CC(EdgeWeightedGraph G)
Computes the connected components of the edge-weighted graphG
.- 参数:
G
- the edge-weighted graph
-
-
方法详细资料
-
id
public int id(int v)
Returns the component id of the connected component containing vertexv
.- 参数:
v
- the vertex- 返回:
- the component id of the connected component containing vertex
v
- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
-
size
public int size(int v)
Returns the number of vertices in the connected component containing vertexv
.- 参数:
v
- the vertex- 返回:
- the number of vertices in the connected component containing vertex
v
- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
-
count
public int count()
Returns the number of connected components in the graphG
.- 返回:
- the number of connected components in the graph
G
-
connected
public boolean connected(int v, int w)
Returns true if verticesv
andw
are in the same connected component.- 参数:
v
- one vertexw
- the other vertex- 返回:
true
if verticesv
andw
are in the same connected component;false
otherwise- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
java.lang.IllegalArgumentException
- unless0 <= w < V
-
areConnected
@Deprecated public boolean areConnected(int v, int w)
已过时。Replaced byconnected(int, int)
.Returns true if verticesv
andw
are in the same connected component.- 参数:
v
- one vertexw
- the other vertex- 返回:
true
if verticesv
andw
are in the same connected component;false
otherwise- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
java.lang.IllegalArgumentException
- unless0 <= w < V
-
main
public static void main(java.lang.String[] args)
Unit tests theCC
data type.- 参数:
args
- the command-line arguments
-
-