Search code examples
javahead

Head/Tail in lists Java


Is it possible for a Linked list to have null header but not a null tail? I mean when the header is null does this mean that the list is empty?


Solution

  • That doesn't make much sense from a logical point of view does it? So no.

    Especially if you look at the actual implementation of the LinkedList in Java which uses one element as both head and tail (the last element of the list is the prev element of the dummy node, the first element of the list is the next element).