FundamentalsFundamentals
Singly Linked List
The simplest linked list: each node has a value and one `next` pointer, so traversal is forward-only and deletion needs the predecessor.
empty list
1/30Start with an empty list: head = null. Each node stores a value and a single `next` pointer, so traversal is one-directional.
VisitingInsertedRemovedMatch
PseudocodeLearn Singly Linked List →
1append(v): walk to the tail; tail.next = Node(v)2prepend(v): node = Node(v); node.next = head; head = node3insert(v, i): walk to node i-1; node.next = prev.next; prev.next = node4delete(v): walk until curr.value == v; prev.next = curr.next5reverse(): prev = null; curr = head6 while curr: next = curr.next; curr.next = prev; prev = curr; curr = next7 head = prevVariables
size0
Complexity
access O(n)
search O(n)
insert O(1)
delete O(1)
Speed