length<T> static method

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

Gets the length of a linked list

head - The head of the linked list Returns the number of nodes in the list

Implementation

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

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

  return count;
}