deleteNode<T> method
Deletes an existing node identified by specified key. This method returns a new list with the specified node removed.
Implementation
List<Node> deleteNode<T>(String key, {Node? parent}) {
List<Node> _children = parent == null ? this.children : parent.children;
List<Node<T>> _filteredChildren = [];
Iterator iter = _children.iterator;
while (iter.moveNext()) {
Node<T> child = iter.current;
if (child.key != key) {
if (child.isParent) {
_filteredChildren.add(child.copyWith(
children: deleteNode<T>(key, parent: child),
));
} else {
_filteredChildren.add(child);
}
}
}
return _filteredChildren;
}