public class DisjointSetForest extends Object
Constructor and Description |
---|
DisjointSetForest(int numberOfElements)
Initialize a disjoint set forest with a number of elements.
|
Modifier and Type | Method and Description |
---|---|
int |
get(int i)
Get the value of the forest at this index - note that this will not
necessarily give the set for that element : use
getSets() after
union-ing elements. |
int |
getRoot(int element)
Travel up the tree that this element is in, until the root of the set
is found, and return that root.
|
int[][] |
getSets()
Retrieve the sets as 2D-array of ints.
|
void |
makeUnion(int elementX,
int elementY)
Union these two elements - in other words, put them in the same set.
|
String |
toString() |
public DisjointSetForest(int numberOfElements)
numberOfElements
- the number of elements in the forestpublic int get(int i)
getSets()
after
union-ing elements.i
- the index in the forestpublic int getRoot(int element)
element
- the starting pointpublic void makeUnion(int elementX, int elementY)
elementX
- an elementelementY
- an elementpublic int[][] getSets()
Copyright © 2018. All Rights Reserved.