diff --git a/swift/08_stack/StackBasedOnLinkedList.swift b/swift/08_stack/StackBasedOnLinkedList.swift index 0e11ce7..d92df90 100644 --- a/swift/08_stack/StackBasedOnLinkedList.swift +++ b/swift/08_stack/StackBasedOnLinkedList.swift @@ -14,8 +14,10 @@ struct StackBasedOnLinkedList: Stack { var size: Int { var count = 0 - while head.next != nil { + var cur = head.next + while cur != nil { count += 1 + cur = cur?.next } return count }