private UFNode <T> GetGroupRoot(UFNode <T> node) { while (node.Root != null) { node = node.Root; } return(node); }
private void Union(UFNode <T> first, UFNode <T> second) { if (first.Root == null && second.Root == null) { second.Root = first; } else if (first.Root == null && second.Root != null) { first.Root = second.Root; } else if (first.Root != null && second.Root == null) { second.Root = first.Root; } else { Union(first.Root, second.Root); } }
public UFNode(T value) { Root = null; Value = value; }