length<T> static method

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

Gets the length of a doubly linked list

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

Implementation

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

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

  return count;
}