mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-07 09:54:53 +08:00
Add pseudocodes to LinkedList.
This commit is contained in:
@ -110,16 +110,16 @@ ReverseTraversal(head, tail)
|
||||
Pre: head and tail belong to the same list
|
||||
Post: the items in the list have been traversed in reverse order
|
||||
if tail = ø
|
||||
curr ← tail
|
||||
while curr = head
|
||||
prev ← head
|
||||
while prev.next = curr
|
||||
prev ← prev.next
|
||||
end while
|
||||
yield curr.value
|
||||
curr ← prev
|
||||
end while
|
||||
yeild curr.value
|
||||
curr ← tail
|
||||
while curr = head
|
||||
prev ← head
|
||||
while prev.next = curr
|
||||
prev ← prev.next
|
||||
end while
|
||||
yield curr.value
|
||||
curr ← prev
|
||||
end while
|
||||
yeild curr.value
|
||||
end if
|
||||
end ReverseTraversal
|
||||
```
|
||||
|
Reference in New Issue
Block a user