Lists & Stacks Hard
Circular Singly Linked List
Follow the source's sentinel-based circular singly linked list: enqueue appends at the tail, remove deletes an indexed item, and iterator next() checks a modification counter.
Advanced input, scenarios & complexity
Trace input
Bounded JSONEdit the exact operation sequence, then build a deterministic trace.
Source scenarios
Complexity
Bestenqueue O(1); remove O(1) at index 0
Averageenqueue O(1); remove O(n)
Worstenqueue O(1); remove O(n)
SpaceO(n)
Data structure in memory
Follow the active references as the source executes.
Operation result
Current stepReady to explore
Source behavior & common mistakes
Trace the dummy node, last pointer, n - 1 public size, link rewiring, and fail-fast iterator behavior. Null payloads are allowed by the Java source.
- The source counter n includes one dummy sentinel; size() returns n - 1.
- The sentinel is identified by node reference, so a null item is still a valid payload.
- Removing the tail repairs last to its predecessor before unlinking the node.
- enqueue and remove increment nOp before work, and iterator next() checks nOp while hasNext() does not.
- Even an invalid remove increments nOp before throwing IndexOutOfBoundsException.
Algorithm code
JavaCircularLinkedList.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1
Comparisons 0 · Writes 0
Understand this operation
Scroll through the stored teaching scenes. The Theater keeps your place.