insertChild

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

Inserts child as a direct child of this node at the given index, shifting any existing children at and after index one position to the right.

Parameters

index

the position at which to insert child; must be in 0..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).