|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.DisjointSetLinkedList
Linked-list implementation of disjoint-set union, using the weighted-union heuristic, as given on pages 502-503 of Introduction to Algorithms, Second edition.
The representative pointer is different here from in the book. In order to be able to get to the information for a set, the representative here references the set, rather than the first node in the set's list.
Nested Class Summary | |
private static class |
DisjointSetLinkedList.DisjointSet
Private inner class for each disjoint set. |
static class |
DisjointSetLinkedList.DisjointSetUnionException
Inner class for an exception that occurs if either set to be united is empty. |
private static class |
DisjointSetLinkedList.Node
Private inner class for nodes of the list. |
Constructor Summary | |
DisjointSetLinkedList()
|
Method Summary | |
private void |
append(DisjointSetLinkedList.DisjointSet first,
DisjointSetLinkedList.DisjointSet second)
Appends one set's list to another set's list. |
java.lang.Object |
findSet(java.lang.Object x)
Returns the object that serves as the representative of the set containing an object. |
java.lang.Object |
makeSet(java.lang.Object x)
Makes a singleton set containing an object. |
java.lang.String |
printSet(java.lang.Object x)
Returns the String representation of the set
containing a given object. |
void |
union(java.lang.Object x,
java.lang.Object y)
Unites two sets, identified by handles to objects in the sets. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DisjointSetLinkedList()
Method Detail |
public java.lang.Object makeSet(java.lang.Object x)
makeSet
in interface DisjointSetUnion
x
- The object in the singleton set.
public void union(java.lang.Object x, java.lang.Object y)
union
in interface DisjointSetUnion
x
- Handle to an object in one set.y
- Handle to an object in the other set.
java.lang.ClassCastException
- if either x
or
y
does not reference a DisjointSet
object.private void append(DisjointSetLinkedList.DisjointSet first, DisjointSetLinkedList.DisjointSet second)
first
- The set to which the other will be appended.second
- The set that will be appended to the other.
DisjointSetLinkedList.DisjointSetUnionException
- if either set is empty.public java.lang.Object findSet(java.lang.Object x)
findSet
in interface DisjointSetUnion
x
- Handle to the object.
java.lang.ClassCastException
- if x
is not a reference
to a Node
object.public java.lang.String printSet(java.lang.Object x)
String
representation of the set
containing a given object.
x
- The object whose set's String
representation is returned.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |