Example #1
0
 void remove() {
   UFNode root = this.find();
   if (root != this) for (UFNode child : children) child.parent = root;
   else if (!children.isEmpty()) {
     Iterator<UFNode> it = children.iterator();
     root = it.next();
     root.parent = null;
     while (it.hasNext()) it.next().parent = root;
     root.size = this.size;
   }
   root.size--;
   this.parent = null;
   this.size = 1;
 }