Lists in action
See what changes in a Python list and a linked list.
Python list
Linked list
The same nodes stay connected. Only their values change.
Compared pairFinished positions
Both take O(n²) time. Links do not make bubble sort faster.
Python code
This is the slide algorithm: it keeps making passes even if the values are already sorted.
Documents are waiting to print. Cancel a job before it starts.
Doubly linked list
Python list positions
A linked list can remove a known node without shifting later references.
Cancel by job ID
jobs is a dictionary: job ID → node.
Lookup takes O(1) time on average. Reconnecting the two links takes O(1).
Finding the job by walking through the list would take O(n).
header and trailer are the empty end nodes from our doubly linked list class.