bool Merge(KruskalNode other) { KruskalNode rootThis = this.Root(); KruskalNode rootOther = other.Root(); if (rootThis == rootOther) { return(false); } if (rootThis.height < rootOther.height) { rootThis.parent = rootOther; } else { rootOther.parent = rootThis; if (rootThis.height == rootOther.height) { rootThis.height += 1; } } return(true); // merge successful }
bool InSameSet(KruskalNode other) { return(this.Root() == other.Root()); }