Skip to content

Commit d97d22a

Browse files
Merge pull request wangzheng0822#267 from IceBlackTea/master
修复 size getter 方法导致的死循环
2 parents e0cd3f7 + cf40a77 commit d97d22a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

swift/08_stack/StackBasedOnLinkedList.swift

Lines changed: 3 additions & 1 deletion
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)