mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 00:46:28 +08:00
docs: add comments of the complexity to queue and deque
This commit is contained in:
parent
595aa93996
commit
007fbff65f
4 changed files with 4 additions and 0 deletions
|
@ -27,6 +27,7 @@ enum Deque {
|
||||||
print("队尾元素 peekLast = \(peekLast)")
|
print("队尾元素 peekLast = \(peekLast)")
|
||||||
|
|
||||||
/* 元素出队 */
|
/* 元素出队 */
|
||||||
|
// 使用 Array 模拟时 pollFirst 的复杂度为 O(n)
|
||||||
let pollFirst = deque.removeFirst()
|
let pollFirst = deque.removeFirst()
|
||||||
print("队首出队元素 pollFirst = \(pollFirst),队首出队后 deque = \(deque)")
|
print("队首出队元素 pollFirst = \(pollFirst),队首出队后 deque = \(deque)")
|
||||||
let pollLast = deque.removeLast()
|
let pollLast = deque.removeLast()
|
||||||
|
|
|
@ -25,6 +25,7 @@ enum Queue {
|
||||||
print("队首元素 peek = \(peek)")
|
print("队首元素 peek = \(peek)")
|
||||||
|
|
||||||
/* 元素出队 */
|
/* 元素出队 */
|
||||||
|
// 使用 Array 模拟时 poll 的复杂度为 O(n)
|
||||||
let pool = queue.removeFirst()
|
let pool = queue.removeFirst()
|
||||||
print("出队元素 poll = \(pool),出队后 queue = \(queue)")
|
print("出队元素 poll = \(pool),出队后 queue = \(queue)")
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,7 @@ comments: true
|
||||||
let peekLast = deque.last! // 队尾元素
|
let peekLast = deque.last! // 队尾元素
|
||||||
|
|
||||||
/* 元素出队 */
|
/* 元素出队 */
|
||||||
|
// 使用 Array 模拟时 pollFirst 的复杂度为 O(n)
|
||||||
let pollFirst = deque.removeFirst() // 队首元素出队
|
let pollFirst = deque.removeFirst() // 队首元素出队
|
||||||
let pollLast = deque.removeLast() // 队尾元素出队
|
let pollLast = deque.removeLast() // 队尾元素出队
|
||||||
|
|
||||||
|
|
|
@ -246,6 +246,7 @@ comments: true
|
||||||
let peek = queue.first!
|
let peek = queue.first!
|
||||||
|
|
||||||
/* 元素出队 */
|
/* 元素出队 */
|
||||||
|
// 使用 Array 模拟时 poll 的复杂度为 O(n)
|
||||||
let pool = queue.removeFirst()
|
let pool = queue.removeFirst()
|
||||||
|
|
||||||
/* 获取队列的长度 */
|
/* 获取队列的长度 */
|
||||||
|
|
Loading…
Reference in a new issue