1.2 KiB
1.2 KiB
Reverse Linked List — PlantUML Diagrams
This directory contains PlantUML diagrams for the three-pointer linked list reversal algorithm.
The diagrams use a small list:
1 -> 2 -> 3 -> null
and show how it becomes:
3 -> 2 -> 1 -> null
Files
00_initial_state.puml— initial state before the loop01_save_next.puml— savingnext = current->next02_reverse_current_link.puml— reversingcurrent->next03_move_pointers.puml— movingpreviousandcurrent04_second_iteration.puml— state after the second node is processed05_final_state.puml— final state after the loop
Generate PNG Files
plantuml diagrams/*.puml
Generate SVG Files
plantuml -tsvg diagrams/*.puml
Core Idea
During the loop, the list is logically split into two parts:
previouspoints to the already reversed partcurrentpoints to the node currently being processednexttemporarily preserves access to the remaining original list
The key operation is:
current->next = previous;
But this is only safe after saving:
Node* next = current->next;
Otherwise the remaining part of the original list would be lost.