J.E.D.I
Figure 1.114 Concatenation of Two Lists
7.4.4 Singly-Linked List with Header Nodes
A header node could be used to contain additional information about the list, say the number of elements. The header node is also known as the list head. For a circular list,
it serves as a sentinel to indicate full traversal of the list. It also indicates either the starting or the end point. For doubly-linked list, it is used to point to both ends, to make
insertion or storage deallocation faster. List head is also used to represent the empty list by a non-null object in an object-oriented programming language like Java, so that
methods such as insertion can be invoked on an empty list. The following figure illustrates a circular list with a list head:
Figure 1.115 Singly-Linked List with List Head
7.4.5 Doubly-Linked List
Doubly-linked lists are formed from nodes that have pointers to both left and right neighbors in the list. The following figure shows the node structure for a doubly-linked
list.
Data Structures 133
J.E.D.I
Figure 1.116 Doubly-Linked List Node Structure The following is an example of a doubly-linked list:
Figure 1.117 Doubly-Linked List With doubly-linked list, each node has two pointer fields - LLINK and RLINK that points
to left and right neighbors respectively. The list can be traversed in either direction. A node i can be deleted knowing only the information about node i. Also, a node j could be
inserted either before or after a node i by knowing the information about i. The following figure illustrates deletion of node i:
Figure 1.118 Deletion from a Doubly-Linked List A doubly-linked list could be constituted in the following ways:
• Doubly-linked linear list • Doubly-linked circular list
• Doubly-linked circular list with list head
Properties of Doubly-Linked List
• LLINKL = RLINKL = L means list L is empty. • We can delete any node, say node
α , in L in O1 time, knowing only the address
α .
• We can insert a new node, say node β
, to the left or right of any node, say node α
, in O1 time, by knowing only α
since it only needs pointer reassignments, as illustrated below:
Data Structures 134
J.E.D.I
Figure 1.119 Insertion into a Doubly-Linked List
7.5 Application: Polynomial Arithmetic