Chapter 5 · Simulation

Circular Linked List Simulator

← Chapter 5
Ready.

Circular Linked List Simulator

In a circular singly linked list the last node points back to the first. A single LAST pointer is all you need: the first node is LAST.next, so both ends are reachable in O(1) time.

How to use it

  • With a Value: Add First, Add Last, Remove First, Remove Last (up to 10 nodes).
  • With an Index: Add at Index, Remove at Index. Rotate moves LAST one step forward; Clear empties the ring.
  • Search and Traverse use a do-while loop that stops once it is back at the start.
  • Josephus: every k-th node (step k) is removed until a single survivor is left.
  • Cancel stops the running animation.

Costs

OperationTime
Add first / last, remove first, rotateO(1)
Remove last (needs the node before it)O(n)
Search, traversal, operations by indexO(n)
Josephus simulationO(n·k)