Skip to content

Commit aa900e3

Browse files
authored
Update reverse function in LinkedList
Add `tail = node` to update tail.
1 parent bc18bf6 commit aa900e3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Linked List/README.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ How about reversing a list, so that the head becomes the tail and vice versa? Th
451451
```swift
452452
public func reverse() {
453453
var node = head
454+
tail = node // If you had a tail pointer
454455
while let currentNode = node {
455456
node = currentNode.next
456457
swap(&currentNode.next, &currentNode.previous)

0 commit comments

Comments
 (0)