Skip to content

Commit b9d8e4f

Browse files
committed
Merge pull request kodecocodes#92 from rinat-gabdullin/master
Fixing deallocation of LinkedListNode
2 parents ba69a89 + 40a43c8 commit b9d8e4f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Linked List/LinkedList.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class LinkedListNode<T> {
77
var value: T
88
var next: LinkedListNode?
9-
var previous: LinkedListNode?
9+
weak var previous: LinkedListNode?
1010

1111
public init(value: T) {
1212
self.value = value
@@ -159,9 +159,9 @@ extension LinkedList {
159159
public func reverse() {
160160
var node = head
161161
while let currentNode = node {
162+
node = currentNode.next
162163
swap(&currentNode.next, &currentNode.previous)
163164
head = currentNode
164-
node = currentNode.previous
165165
}
166166
}
167167
}

0 commit comments

Comments
 (0)