From cf40a772680ce1cee83816122625dbc371ece9ae Mon Sep 17 00:00:00 2001 From: Xummer Date: Mon, 11 Mar 2019 23:12:30 +0800 Subject: [PATCH] Fixing the size getter leads to infinite loop. --- swift/08_stack/StackBasedOnLinkedList.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 }