Delete 4
Code:
Head
|
v
+---+ +---+ +---+ +---+ +---+
| 5 |--->| 4 |--->| 3 |--->| 2 |--->| 1 |--->NULL
+---+ +---+ +---+ +---+ +---+
Step 1, advance current to the correct node.
Code:
Head current
| |
v v
+---+ +---+ +---+ +---+ +---+
| 5 |--->| 4 |--->| 3 |--->| 2 |--->| 1 |--->NULL
+---+ +---+ +---+ +---+ +---+
Step 2, bypass the node to be deleted.
Somehow, you need to make the node containing 5 point to the node containing 3.
Code:
Head current
| |
v v
+---+ +---+ +---+ +---+ +---+
| 5 |-+ | 4 | +->| 3 |--->| 2 |--->| 1 |--->NULL
+---+ | +---+ | +---+ +---+ +---+
+--------+
This is normally achieved by having another pointer variable that tracks the previous node.