diff --git a/codes/swift/chapter_stack_and_queue/deque.swift b/codes/swift/chapter_stack_and_queue/deque.swift index 205da4055..6638eacb3 100644 --- a/codes/swift/chapter_stack_and_queue/deque.swift +++ b/codes/swift/chapter_stack_and_queue/deque.swift @@ -27,6 +27,7 @@ enum Deque { print("队尾元素 peekLast = \(peekLast)") /* 元素出队 */ + // 使用 Array 模拟时 pollFirst 的复杂度为 O(n) let pollFirst = deque.removeFirst() print("队首出队元素 pollFirst = \(pollFirst),队首出队后 deque = \(deque)") let pollLast = deque.removeLast() diff --git a/codes/swift/chapter_stack_and_queue/queue.swift b/codes/swift/chapter_stack_and_queue/queue.swift index f13af36f5..ea1e94722 100644 --- a/codes/swift/chapter_stack_and_queue/queue.swift +++ b/codes/swift/chapter_stack_and_queue/queue.swift @@ -25,6 +25,7 @@ enum Queue { print("队首元素 peek = \(peek)") /* 元素出队 */ + // 使用 Array 模拟时 poll 的复杂度为 O(n) let pool = queue.removeFirst() print("出队元素 poll = \(pool),出队后 queue = \(queue)") diff --git a/docs/chapter_stack_and_queue/deque.md b/docs/chapter_stack_and_queue/deque.md index e4674d5f1..b8d4df9ad 100644 --- a/docs/chapter_stack_and_queue/deque.md +++ b/docs/chapter_stack_and_queue/deque.md @@ -212,6 +212,7 @@ comments: true let peekLast = deque.last! // 队尾元素 /* 元素出队 */ + // 使用 Array 模拟时 pollFirst 的复杂度为 O(n) let pollFirst = deque.removeFirst() // 队首元素出队 let pollLast = deque.removeLast() // 队尾元素出队 diff --git a/docs/chapter_stack_and_queue/queue.md b/docs/chapter_stack_and_queue/queue.md index d70b3e528..aaba7da43 100644 --- a/docs/chapter_stack_and_queue/queue.md +++ b/docs/chapter_stack_and_queue/queue.md @@ -246,6 +246,7 @@ comments: true let peek = queue.first! /* 元素出队 */ + // 使用 Array 模拟时 poll 的复杂度为 O(n) let pool = queue.removeFirst() /* 获取队列的长度 */