we say that a header linked list is that which consists of a special node called header node that marks the beginning of the list
but i dont understand what is really the importance of this header node.
please help me?
we say that a header linked list is that which consists of a special
Share
Having sentinel nodes prevents you from having to handle certain edge cases.
The biggest is the null check: You always know that there will be a node at the top of the list that you can insert nodes after, so you don’t have to deal with checking if head is null. (also it helps having a tail node for similar reasons)
Consider the two cases:
With a head and a tail node:
Without:
the intent of the first one is a lot clearer because it is like inserting anywhere else. The second case requires you to check for a special circumstance.