public DisjointSet <T> Find() { if (this.root != this) { this.root = this.root.Find(); } return(this.root); }
public void Union(DisjointSet <T> other) { var thisRoot = Find(); var otherRoot = other.Find(); if (thisRoot == otherRoot) { return; } if (thisRoot.rank < otherRoot.rank) { thisRoot.root = otherRoot; } else if (thisRoot.rank > otherRoot.rank) { otherRoot.root = thisRoot; } else { otherRoot.root = thisRoot; thisRoot.rank++; } }
public DisjointSet() { root = this; }