getLength<T> function

int getLength<T>(
  1. LinkedListNode<T>? head
)

Helper function to get the length of a linked list

head - The head of the linked list Returns the length of the linked list

Implementation

int getLength<T>(LinkedListNode<T>? head) {
  int length = 0;
  LinkedListNode<T>? current = head;

  while (current != null) {
    length++;
    current = current.next;
  }

  return length;
}