removeFirst method

T? removeFirst()

Removes and returns the first node data from this list. This method returns null if the list is empty.

Implementation

T? removeFirst() {
  if (_head == null) return null;
  T? removedData = _head!.data;
  if (_head == _tail) {
    _head = _tail = null;
  } else {
    _head = _head!.next;
  }
  _size--;
  return removedData;
}