Unify the function naming of

queue from `offer()` to `push()`
This commit is contained in:
Yudong Jin
2023-02-02 01:43:01 +08:00
parent a0ee691475
commit 7d14c9440e
29 changed files with 184 additions and 189 deletions

View File

@ -31,7 +31,7 @@ class ArrayQueue {
}
/* */
func offer(num: Int) {
func push(num: Int) {
if size() == capacity() {
print("队列已满")
return
@ -82,11 +82,11 @@ enum _ArrayQueue {
let queue = ArrayQueue(capacity: capacity)
/* */
queue.offer(num: 1)
queue.offer(num: 3)
queue.offer(num: 2)
queue.offer(num: 5)
queue.offer(num: 4)
queue.push(num: 1)
queue.push(num: 3)
queue.push(num: 2)
queue.push(num: 5)
queue.push(num: 4)
print("队列 queue = \(queue.toArray())")
/* 访 */
@ -107,7 +107,7 @@ enum _ArrayQueue {
/* */
for i in 0 ..< 10 {
queue.offer(num: i)
queue.push(num: i)
queue.poll()
print("\(i) 轮入队 + 出队后 queue = \(queue.toArray())")
}

View File

@ -25,7 +25,7 @@ class LinkedListQueue {
}
/* */
func offer(num: Int) {
func push(num: Int) {
// num
let node = ListNode(x: num)
//
@ -79,11 +79,11 @@ enum _LinkedListQueue {
let queue = LinkedListQueue()
/* */
queue.offer(num: 1)
queue.offer(num: 3)
queue.offer(num: 2)
queue.offer(num: 5)
queue.offer(num: 4)
queue.push(num: 1)
queue.push(num: 3)
queue.push(num: 2)
queue.push(num: 5)
queue.push(num: 4)
print("队列 queue = \(queue.toArray())")
/* 访 */