#include <DisjSets.h>
Public Member Functions | |
| DisjSets (int numElements) | |
| int | find (int x) const |
| int | find (int x) |
| void | unionSets (int root1, int root2) |
Disjoint set class. Use union by rank and path compression. Elements in the set are numbered starting at 0.
Definition at line 22 of file DisjSets.h.
|
explicit |
Construct the disjoint sets object. numElements is the initial number of disjoint sets.
Definition at line 7 of file DisjSets.cpp.
| int DisjSets::find | ( | int | x | ) |
Perform a find with path compression. Error checks omitted again for simplicity. Return the set containing x.
Definition at line 50 of file DisjSets.cpp.
| int DisjSets::find | ( | int | x | ) | const |
Perform a find. Error checks omitted again for simplicity. Return the set containing x.
Definition at line 36 of file DisjSets.cpp.
| void DisjSets::unionSets | ( | int | root1, |
| int | root2 | ||
| ) |
Union two disjoint sets. For simplicity, we assume root1 and root2 are distinct and represent set names. root1 is the root of set 1. root2 is the root of set 2.
Definition at line 18 of file DisjSets.cpp.