Linked list visualiser
A singly linked list is a chain of nodes, each holding a value and the address of the next node, with start pointing at the first. Type a starting list and the operations to run, then press Play: new nodes are made and linked in, the pointers start, p, prev, curr and next move along the arrows, a reversal turns the arrows round one by one, and the Java line that is running is lit.
How to use it
- 1Type the numbers the list starts with (or none) and the operations to run, e.g. addfirst 5, delete 20, reverse, or tap an example.
- 2Press Show me, then Play. New nodes are made and linked in, and the pointers start, p, prev, curr and next move along the arrows.
- 3Watch each arrow change and the Java line that is running. Use Back and Next, the slider or the arrow keys to go at your own speed.
The animation needs JavaScript. Every step is written out below.
Result
- Result
- 40 → 30 → 20 → 10 (4 nodes)
Every step in words (26 steps)
- The list starts as 10 → 20 → 30 → 40.
- reverse() is called: every next pointer will be turned round, one node at a time.
- prev = null, curr = start: prev is the node already turned, curr the one to turn next.
- curr != null (curr holds 10): there is another node to turn.
- next = curr.next: remember the node after 10 (20) before its pointer changes.
- curr.next = prev: the pointer of 10 now points backwards, at null.
- prev = curr: prev moves up to the node just turned.
- curr = next: curr moves on to 20.
- curr != null (curr holds 20): there is another node to turn.
- next = curr.next: remember the node after 20 (30) before its pointer changes.
- curr.next = prev: the pointer of 20 now points backwards, at 10.
- prev = curr: prev moves up to the node just turned.
- curr = next: curr moves on to 30.
- curr != null (curr holds 30): there is another node to turn.
- next = curr.next: remember the node after 30 (40) before its pointer changes.
- curr.next = prev: the pointer of 30 now points backwards, at 20.
- prev = curr: prev moves up to the node just turned.
- curr = next: curr moves on to 40.
- curr != null (curr holds 40): there is another node to turn.
- next = curr.next: remember the node after 40 (null) before its pointer changes.
- curr.next = prev: the pointer of 40 now points backwards, at 30.
- prev = curr: prev moves up to the node just turned.
- curr = next: curr moves on to null.
- curr is null: every pointer has been turned round.
- start = prev: start points at the old last node (40), which is now the first.
- Drawn again from start, the list reads: 40 → 30 → 20 → 10.
About the Linked list visualiser
What it does
Runs operations on a singly linked list one pointer change at a time. Every node is a box holding a value and an arrow to the next node, start points at the first node and the last node's next is null. A new node is made (shown below the row until it is linked in), the pointers that walk the list are labelled above the node they point at, a deleted node is marked and then removed, and the Java line that is running is lit. A reversal turns the arrows round one by one, with prev, curr and next shown, and then draws the list again from start.
The operations
- addfirst x, addlast x: add a node at the start or at the end.
- insertat p x: make x node number p (1 is the first node).
- deletefirst, deletelast: remove the first or the last node.
- delete x: remove the first node that holds x.
- search x, traverse: look for x; visit every node and print its value.
- reverse: turn every next pointer round.
The limits
A starting list of up to 8 numbers, at most 10 nodes at any time, up to 20 operations, each number from -99 to 999. Deleting from an empty list does nothing and the sentence is shown in red.
Common questions
What is a singly linked list?
A chain of nodes, each holding some data and a reference to the next node. A reference called start (or head) points at the first node and the last node's next is null. Unlike an array it can grow and shrink without moving the other values.
How do you insert a node at the end of a linked list?
Make the new node, then, if start is null, make start point at it; otherwise walk a pointer p along the list until p.next is null and set p.next to the new node.
How do you reverse a singly linked list?
Keep three pointers: prev (null at first), curr (start) and next. For each node save next = curr.next, turn the pointer round with curr.next = prev, then move prev and curr on. When curr is null, set start = prev.
What happens when you delete from an empty linked list?
start is null, so there is no node to delete; the method must check this first (if (start == null) return;) or it would fail with a NullPointerException.
Can I see the code in Python, JavaScript or C++?
Yes. Choose the language in the menu above the code. Only the listing changes: the steps are always worked out from the Java program that ISC uses, and the highlighted line moves to the matching line of the language you chose.
Practise on real ISC questions
- What is the importance of the reference part in a Linked List?2023
- A linked list is formed from the objects of the class Node. The class structure of the Node is given below: ……2020
- State the difference between a Binary Tree structure and a single Linked List.2020
- A linked list is formed from the objects of the class Word. The structure of the class Word is given below: ……2026
- ___________ is called a Self-Referential Data structure.2025 Practice
- A linked list is formed from the objects of the class given below: … Write an Algorithm OR a Method to add a…2023
- A linked list is formed from the objects of the class Cell. The class structure of the Cell is given below: ……2025
- A linked list is formed from the objects of the class Node. The class structure of the Node is given below: ……2020 Specimen
- A linked list is formed from the objects of the class Node. The class structure of the Node is given below: ……2018
- A linked list is formed from the objects of the class Node. The structure of the class Node is given below: ……2026 Improvement
More Computer Science tools
- Boolean algebra solverSimplify any expression: the laws step by step, truth table, K-map and the logic circuit.
- Infix to postfix converterInfix to postfix or prefix with the stack table, and postfix evaluation step by step.
- Binary tree and BST toolBuild a binary search tree, rebuild a tree from two traversals, and get every traversal and fact.
- Stack and queue simulatorRun push, pop, insert and delete on a stack, queue, circular queue or dequeue, and watch the pointers move.
- Recursion visualiserWatch factorial, Fibonacci, power, GCD and sum of digits run: the calls, the call stack and the returns.
- Tower of Hanoi visualiserWatch the discs move between the pegs while the recursive calls and the call stack build up.
- Binary search tree visualiserWatch values being inserted into a binary search tree, searched for, and walked inorder, preorder and postorder.
- Binary tree traversal visualiserClick a binary tree together and watch preorder, inorder and postorder walk it, with the recursive calls on the call stack.
- Stack and queue visualiserWatch push, pop, insert and delete move top, front and rear along the array, with overflow and underflow.
- 2D array visualiserWatch row-wise, column-wise, diagonal, boundary and spiral walks number the cells of a 2D array in the order they print.
- Sorting visualiserWatch bubble, selection and insertion sort compare, swap and shift your own list, step by step.
- Linear and binary search visualiserWatch a linear or binary search look for a value in your list, and count the comparisons.