getAll method

List<T?>? getAll()

Gets all nodes data in this LinkedList and then returns them as type List. This method returns null if the list is empty.

Implementation

List<T?>? getAll() {
  if (_head == null) return null;
  if (_head == _tail) return [_head!.data];
  List<T?> nodes = [];
  _Node<T>? last = _head;
  while (last != null) {
    nodes.add(last.data);
    last = last.next;
  }
  return nodes;
}