replaceChild

fun replaceChild(index: Int, child: TreeNode<T>): TreeNode<T>(source)

Replaces the direct child at the given index with child, detaching the previous child (its parent becomes null).

Return

the previous child that was at index, now detached.

Parameters

index

the position of the child to replace; must be in 0 until children.size.

child

a node that is not already attached to a tree. To move a node that already has a parent, call detach on it first.

Throws

if index is out of range.

if child already has a parent, or if attaching it here would create a cycle (i.e. child is this node or one of its ancestors).