In an endpoint-based double-ended queue represented by a doubly linked list, the first and last references are both null exactly when the double-ended queue is empty. Otherwise the first node has null predecessor, the last has null successor, and the finite successor chain is acyclic.
The two directions must agree: if node has successor , then has predecessor , and conversely for a nonnull predecessor. Thus following successors and following predecessors visit the same linked list nodes in reverse order.
Removing the only linked list node must clear both endpoints. Clearing only the endpoint used by that operation would leave one traversal apparently empty and the reverse traversal still reaching the removed node. The representation invariant makes that error visible before it affects later operations.
Articles by others on the same topic
There are currently no matching articles.