def tree_predecessor(x): if left[x] != NIL: return tree_maximum(left[x]) z = x y = parent[z] while y != NIL and z == left[y]: z = y y = parent[y] return y
def link(x, y): if rank[x] > rank[y]: p[y] = x else p[x] = y if rank[x] == rank[y]: rank[y] = rank[y] + 1
def find_set(x): if x != p[x]: p[x] = find_set(p[x]) return p[x]