Java Reference
In-Depth Information
Doubly Linked List
An ordinary linked list allows you to move down the list in only one direction (following
the links). A
doubly linked
list
has one link that has a reference to the next node and
one that has a reference to the previous node. In some cases the link to the previous node
can simplify our code. For example, we will no longer need to have a
previous
instance
variable to remember the node that links to the current position. Diagrammatically, a
doubly linked list looks like the sample list in Display 15.21.
The node class for a doubly linked list can begin as follows:
doubly
linked list
private
class
TwoWayNode
{
private
String item;
private
TwoWayNode previous;
private
TwoWayNode next;
...
Display 15.21
A Doubly Linked List
"shoes"
null
"socks"
"coat"
"gloves"
null