I have one question in my mind that in case of circular doubly linked list the head pointer of the doubly linked list also logically point to the next pointer of the tail node of the linked list and tail's next pointer also point to the previous pointer of head.
Please Answer me this question I am a bit confused.
Best Answer
It depends.
Is it a circular or linear list?
If it's a circular list then there is no "head" or "tail" as each element's
next
andprev
pointers will be set. You can start traversing the list anywhere and have to remember where you started so you know when to stop.If it's a linear list then the
prev
pointer of the head element will benull
and thenext
pointer of the tail element will benull
. You use this information to know when to stop.