public final class DisjointSets
extends java.lang.Object
Constructor and Description |
---|
DisjointSets(int numElements)
Construct a disjoint sets object.
|
Modifier and Type | Method and Description |
---|---|
int |
find(int x)
find() finds the (int) name of the set containing a given element.
|
void |
union(int root1,
int root2)
union() unites two disjoint sets into a single set.
|
public DisjointSets(int numElements)
numElements
- the initial number of elements--also the initial number of
disjoint sets, since every element is initially in its own
set.public void union(int root1, int root2)
root1
- the root of the first set.root2
- the root of the other set.public int find(int x)
x
- the element sought.