Hi I want to know that do "head" and "tail" store any value like the other nodes?? thanks
Head node has a reference to the next node, and a null reference to the previous node.
Tail node has a reference to the previous node, and a null reference to the next done.
Head and tail nodes should be identical to any other node. The only difference being, head
hasn't a reference to a previous node, and tail
hasn't a reference to a next node.
Unless, your implementation is a circularly linked list, where head
references tail
as previous node, and tail
references head
as next node.
A doubly-linked list is a specialized graph data structure.
If you think of a doubly-linked list as a graph, you see every node has data, even if it has only one connection. In a doubly-linked list, which is a complete graph (where there is a path from any given node to any other given node), inner nodes contain two references (one for either direction in the list), and outer nodes (head/tail) contain only one reference (which is a reference back to the node you may have accessed this node from).
Head and tail nodes are only special in that they only have one reference instead of two. They are still part of the graph data structure you are representing.
Depends on the specific implementation of the linked list. Both ways can be made to work, but having extra "head/tail" elements greatly simplifies the implementation of many operations like insert/remove (since you can always be sure there will be a next/previous element, saving a lot of conditional code to deal with the start/end of the list).
Since you tagged your question as Java, i suggest you take a look at the JDK source code of java.util.LinkedList. You will find that in this specific implementation head and tail do not refer to an element.
If you really want to understand the advantage of extra head/tail nodes its probably most instructive if you implement a simple double linked list by yourself to experience the difference in complexity for the insert/remove methods firsthand.
In other languanges that allow pointer arithmetic, there is often only an extra head node which also serves as the tail node at the same time.
As Scot said above the structure of Doubly Linked Lists are shown there. I think it is the Wikipedia Image.
Please refer this link and you will be surely got the idea on it.
http://richardbowles.tripod.com/cpp/linklist/doublist.htm
Head and tail should be identical to all other nodes at the List. But there are bit difference from Circular D. Linked Lists and this features are not dealing with them.
Regarding to the Doubly Linked Lists the difference is head hasn't a reference to a previous node + tail hasn't a reference to a next node. This is a simple data structure for Doubly Linked Lists.