Disjoint-set of the merger by rank

The combined advantages according to the rank: voidable; fast (O (n log n))
. 1  void Combine ( int X, int Y) // Rank for the current node in the tree of depth
 2  {
 . 3      int T1, T2;
 . 4      T1 = Find (X), T2 = Find (Y);
 . 5      IF (Rank [ T1] < Rank [Y]) the swap (T1, T2);
 . 6      Father [T2] = T1;
 . 7      IF (Rank [T1] == Rank [T2]) ++ Rank [T1];
 . 8 }

 

Guess you like

Origin www.cnblogs.com/cptbtptpbcptbtptp/p/11234414.html