Skip to content

Commit

Permalink
docs: add comments of the complexity to queue and deque
Browse files Browse the repository at this point in the history
  • Loading branch information
nuomi1 committed Jan 14, 2023
1 parent 595aa93 commit 007fbff
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions codes/swift/chapter_stack_and_queue/deque.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions codes/swift/chapter_stack_and_queue/queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum Queue {
print("队首元素 peek = \(peek)")

/* 元素出队 */
// 使用 Array 模拟时 poll 的复杂度为 O(n)
let pool = queue.removeFirst()
print("出队元素 poll = \(pool),出队后 queue = \(queue)")

Expand Down
1 change: 1 addition & 0 deletions docs/chapter_stack_and_queue/deque.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ comments: true
let peekLast = deque.last! // 队尾元素

/* 元素出队 */
// 使用 Array 模拟时 pollFirst 的复杂度为 O(n)
let pollFirst = deque.removeFirst() // 队首元素出队
let pollLast = deque.removeLast() // 队尾元素出队

Expand Down
1 change: 1 addition & 0 deletions docs/chapter_stack_and_queue/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ comments: true
let peek = queue.first!

/* 元素出队 */
// 使用 Array 模拟时 poll 的复杂度为 O(n)
let pool = queue.removeFirst()

/* 获取队列的长度 */
Expand Down

0 comments on commit 007fbff

Please sign in to comment.