Skip to content

Commit cf40a77

Browse files
authored
Fixing the size getter leads to infinite loop.
1 parent e0cd3f7 commit cf40a77

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

swift/08_stack/StackBasedOnLinkedList.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ struct StackBasedOnLinkedList<Element>: Stack {
1414

1515
var size: Int {
1616
var count = 0
17-
while head.next != nil {
17+
var cur = head.next
18+
while cur != nil {
1819
count += 1
20+
cur = cur?.next
1921
}
2022
return count
2123
}

0 commit comments

Comments
 (0)