Singly Linked List Basics
Step 1 of 9
head
cur
·
3•
∅
·
7•
·
15•
·
2•
One node is two fields: a value and the address of the next node. A fresh node links to nothing.
The Idea
A linked list stores each value in its own node, and every node keeps the address of the next one. Nothing sits side by side in memory. You hold only the head, and the chain ends at a node pointing to None.
Real-World Example
A scavenger hunt works exactly like this. The card in your hand gives you one prize and one instruction: look behind the oak tree next. Nobody hands you the full route, and clue seven is unreachable until you have opened the six before it.
The Code
Your turn
What does this print?
class Node:
def __init__(self, v):
self.value, self.next = v, None
a = Node(1)
a.next = Node(2)
b = a.next
print(b.value, b.next)Mini quiz
1 / 3