|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectUnionFind
public class UnionFind
Implements a union find set. Initially, the set each index corresponds to is the label. Subsequent calls to union combine the sets, and calls to find return the set it belongs to.
Constructor Summary | |
---|---|
UnionFind(int size)
Creates a union find set of the specified size. |
Method Summary | |
---|---|
int |
find(int x)
Returns the set that element x belongs to. |
void |
union(int x,
int y)
Merges the sets that the parameters belong to. |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UnionFind(int size)
size
- The number of elements.Method Detail |
---|
public void union(int x, int y)
x
- an elementy
- another elementpublic int find(int x)
x
- the element whose set we wish to discover.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |