static list<int> listElements(const DisjointSets &ds, int set) { list<int> elements; for (int i = 0; i < ds.NumElements(); ++i) { if (ds.FindSet(i) == ds.FindSet(set)) elements.push_front(i); } return elements; }
static list<int> listSets(const DisjointSets &ds) { list<int> sets; for (int i = 0; i < ds.NumElements(); ++i) { if (ds.FindSet(i) == i) sets.push_front(i); } return sets; }
void printElementSets(const DisjointSets & s) { for (int i = 0; i < s.NumElements(); ++i) cout << s.FindSet(i) << " "; cout << endl; }