Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
2  
It's not difficult to look this up: en.wikipedia.org/wiki/Doubly_linked_list . –  dan_waterworth Sep 28 '12 at 6:16

2 Answers 2

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 and prev 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 be null and the next pointer of the tail element will be null. You use this information to know when to stop.

share|improve this answer

Assume you have a circular doubly linked list with three nodes at position 1, 2 and 3:

[1] next->2 prev->3
[2] next->3 prev->1
[3] next->1 prev->2

In some sense there is no "head" and "tail" in a circular doubly linked list. Though you will have a pointer outside as an entry point to access the list like head->1, which would be identical to 3:next->1.

So the heads prev points to the "tail"

The tails next points to the "head"

share|improve this answer
2  
'there is no "head" and "tail" in a doubly linked list' - This is only true for circular lists. Which is what the question is about, but IMHO it would be clearer to explicitly mention this in your answer too. –  Péter Török Sep 28 '12 at 7:41
    
Thanks Péter for pointing that out. Updated my answer. –  thorsten müller Sep 28 '12 at 7:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.