Ref: 2 step by step diagrams added.
This commit is contained in:
38
analysis/04-reverse-linked-list/diagrams/01_save_next.puml
Normal file
38
analysis/04-reverse-linked-list/diagrams/01_save_next.puml
Normal file
@@ -0,0 +1,38 @@
|
||||
@startuml
|
||||
title Step 1 — Save next
|
||||
|
||||
object "Node 1" as n1 {
|
||||
value = 1
|
||||
}
|
||||
|
||||
object "Node 2" as n2 {
|
||||
value = 2
|
||||
}
|
||||
|
||||
object "Node 3" as n3 {
|
||||
value = 3
|
||||
}
|
||||
|
||||
n1 --> n2 : next
|
||||
n2 --> n3 : next
|
||||
n3 --> "null" : next
|
||||
|
||||
object "previous" as prev
|
||||
object "current" as cur
|
||||
object "next" as nxt
|
||||
|
||||
prev --> "null"
|
||||
cur --> n1
|
||||
nxt --> n2
|
||||
|
||||
note right of nxt
|
||||
next = current->next
|
||||
|
||||
We save the next node before changing
|
||||
current->next.
|
||||
|
||||
Without this temporary pointer, the rest
|
||||
of the original list would become unreachable.
|
||||
end note
|
||||
|
||||
@enduml
|
||||
Reference in New Issue
Block a user