diff --git a/codes/c/chapter_stack_and_queue/array_queue.c b/codes/c/chapter_stack_and_queue/array_queue.c index 049a3dd87..c6e989125 100644 --- a/codes/c/chapter_stack_and_queue/array_queue.c +++ b/codes/c/chapter_stack_and_queue/array_queue.c @@ -67,8 +67,8 @@ void push(ArrayQueue *queue, int num) { queue->queSize++; } -/* 出队 */ -void poll(ArrayQueue *queue) { +/* 出队 */ +void pop(ArrayQueue *queue) { int num = peek(queue); // 队首指针向后移动一位,若越过尾部则返回到数组头部 queue->front = (queue->front + 1) % queue->queCapacity; @@ -106,8 +106,8 @@ int main() { printf("队首元素 peek = %d\r\n", peekNum); /* 元素出队 */ - poll(queue); - printf("出队元素 poll = %d,出队后 queue = ", peekNum); + pop(queue); + printf("出队元素 pop = %d,出队后 queue = ", peekNum); printArrayQueue(queue); /* 获取队列的长度 */ @@ -121,7 +121,7 @@ int main() { /* 测试环形数组 */ for (int i = 0; i < 10; i++) { push(queue, i); - poll(queue); + pop(queue); printf("第 %d 轮入队 + 出队后 queue = ", i); printArrayQueue(queue); } diff --git a/codes/cpp/chapter_stack_and_queue/array_deque.cpp b/codes/cpp/chapter_stack_and_queue/array_deque.cpp index 83ba85e2f..1b1b122aa 100644 --- a/codes/cpp/chapter_stack_and_queue/array_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/array_deque.cpp @@ -72,7 +72,7 @@ public: } /* 队首出队 */ - int pollFirst() { + int popFirst() { int num = peekFirst(); // 队首指针向后移动一位 front = index(front + 1); @@ -81,7 +81,7 @@ public: } /* 队尾出队 */ - int pollLast() { + int popLast() { int num = peekLast(); queSize--; return num; @@ -139,11 +139,11 @@ int main() { PrintUtil::printVector(deque->toVector()); /* 元素出队 */ - int pollLast = deque->pollLast(); - cout << "队尾出队元素 = " << pollLast << ",队尾出队后 deque = "; + int popLast = deque->popLast(); + cout << "队尾出队元素 = " << popLast << ",队尾出队后 deque = "; PrintUtil::printVector(deque->toVector()); - int pollFirst = deque->pollFirst(); - cout << "队首出队元素 = " << pollFirst << ",队首出队后 deque = "; + int popFirst = deque->popFirst(); + cout << "队首出队元素 = " << popFirst << ",队首出队后 deque = "; PrintUtil::printVector(deque->toVector()); /* 获取双向队列的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/array_queue.cpp b/codes/cpp/chapter_stack_and_queue/array_queue.cpp index eafc8ce24..e00f68f0b 100644 --- a/codes/cpp/chapter_stack_and_queue/array_queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/array_queue.cpp @@ -56,7 +56,7 @@ public: } /* 出队 */ - void poll() { + void pop() { int num = peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 front = (front + 1) % queCapacity; @@ -102,8 +102,8 @@ int main() { cout << "队首元素 peek = " << peek << endl; /* 元素出队 */ - queue->poll(); - cout << "出队元素 poll = " << peek << ",出队后 queue = "; + queue->pop(); + cout << "出队元素 pop = " << peek << ",出队后 queue = "; PrintUtil::printVector(queue->toVector()); /* 获取队列的长度 */ @@ -117,7 +117,7 @@ int main() { /* 测试环形数组 */ for (int i = 0; i < 10; i++) { queue->push(i); - queue->poll(); + queue->pop(); cout << "第 " << i << " 轮入队 + 出队后 queue = "; PrintUtil::printVector(queue->toVector()); } diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp index fefbb7675..60f38e3f4 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_deque.cpp @@ -79,7 +79,7 @@ public: } /* 出队操作 */ - int poll(bool isFront) { + int pop(bool isFront) { // 若队列为空,直接返回 -1 if (isEmpty()) return -1; @@ -110,13 +110,13 @@ public: } /* 队首出队 */ - int pollFirst() { - return poll(true); + int popFirst() { + return pop(true); } /* 队尾出队 */ - int pollLast() { - return poll(false); + int popLast() { + return pop(false); } /* 访问队首元素 */ @@ -166,11 +166,11 @@ int main() { PrintUtil::printVector(deque->toVector()); /* 元素出队 */ - int pollLast = deque->pollLast(); - cout << "队尾出队元素 = " << pollLast << ",队尾出队后 deque = "; + int popLast = deque->popLast(); + cout << "队尾出队元素 = " << popLast << ",队尾出队后 deque = "; PrintUtil::printVector(deque->toVector()); - int pollFirst = deque->pollFirst(); - cout << "队首出队元素 = " << pollFirst << ",队首出队后 deque = "; + int popFirst = deque->popFirst(); + cout << "队首出队元素 = " << popFirst << ",队首出队后 deque = "; PrintUtil::printVector(deque->toVector()); /* 获取双向队列的长度 */ diff --git a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp index 3b1afc26c..5ecb4565c 100644 --- a/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp +++ b/codes/cpp/chapter_stack_and_queue/linkedlist_queue.cpp @@ -52,7 +52,7 @@ public: } /* 出队 */ - void poll() { + void pop() { int num = peek(); // 删除头结点 ListNode *tmp = front; @@ -101,8 +101,8 @@ int main() { cout << "队首元素 peek = " << peek << endl; /* 元素出队 */ - queue->poll(); - cout << "出队元素 poll = " << peek << ",出队后 queue = "; + queue->pop(); + cout << "出队元素 pop = " << peek << ",出队后 queue = "; PrintUtil::printVector(queue->toVector()); /* 获取队列的长度 */ diff --git a/codes/csharp/chapter_stack_and_queue/array_deque.cs b/codes/csharp/chapter_stack_and_queue/array_deque.cs index 916af3a0c..c9a050980 100644 --- a/codes/csharp/chapter_stack_and_queue/array_deque.cs +++ b/codes/csharp/chapter_stack_and_queue/array_deque.cs @@ -81,7 +81,7 @@ namespace hello_algo.chapter_stack_and_queue } /* 队首出队 */ - public int pollFirst() + public int popFirst() { int num = peekFirst(); // 队首指针向后移动一位 @@ -91,7 +91,7 @@ namespace hello_algo.chapter_stack_and_queue } /* 队尾出队 */ - public int pollLast() + public int popLast() { int num = peekLast(); queSize--; @@ -158,10 +158,10 @@ namespace hello_algo.chapter_stack_and_queue Console.WriteLine("元素 1 队首入队后 deque = " + string.Join(" ", deque.toArray())); /* 元素出队 */ - int pollLast = deque.pollLast(); - Console.WriteLine("队尾出队元素 = " + pollLast + ",队尾出队后 deque = " + string.Join(" ", deque.toArray())); - int pollFirst = deque.pollFirst(); - Console.WriteLine("队首出队元素 = " + pollFirst + ",队首出队后 deque = " + string.Join(" ", deque.toArray())); + int popLast = deque.popLast(); + Console.WriteLine("队尾出队元素 = " + popLast + ",队尾出队后 deque = " + string.Join(" ", deque.toArray())); + int popFirst = deque.popFirst(); + Console.WriteLine("队首出队元素 = " + popFirst + ",队首出队后 deque = " + string.Join(" ", deque.toArray())); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/csharp/chapter_stack_and_queue/array_queue.cs b/codes/csharp/chapter_stack_and_queue/array_queue.cs index 9dce56861..5e9e8347b 100644 --- a/codes/csharp/chapter_stack_and_queue/array_queue.cs +++ b/codes/csharp/chapter_stack_and_queue/array_queue.cs @@ -56,7 +56,7 @@ class ArrayQueue } /* 出队 */ - public int poll() + public int pop() { int num = peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 @@ -108,8 +108,8 @@ public class array_queue Console.WriteLine("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.poll(); - Console.WriteLine("出队元素 poll = " + poll + ",出队后 queue = " + string.Join(",", queue.toArray())); + int pop = queue.pop(); + Console.WriteLine("出队元素 pop = " + pop + ",出队后 queue = " + string.Join(",", queue.toArray())); /* 获取队列的长度 */ int size = queue.size(); @@ -123,7 +123,7 @@ public class array_queue for (int i = 0; i < 10; i++) { queue.push(i); - queue.poll(); + queue.pop(); Console.WriteLine("第 " + i + " 轮入队 + 出队后 queue = " + string.Join(",", queue.toArray())); } } diff --git a/codes/csharp/chapter_stack_and_queue/linkedlist_deque.cs b/codes/csharp/chapter_stack_and_queue/linkedlist_deque.cs index 54a01bff7..79e6d4b8c 100644 --- a/codes/csharp/chapter_stack_and_queue/linkedlist_deque.cs +++ b/codes/csharp/chapter_stack_and_queue/linkedlist_deque.cs @@ -90,7 +90,7 @@ namespace hello_algo.chapter_stack_and_queue } /* 出队操作 */ - private int? poll(bool isFront) + private int? pop(bool isFront) { // 若队列为空,直接返回 null if (isEmpty()) @@ -133,15 +133,15 @@ namespace hello_algo.chapter_stack_and_queue } /* 队首出队 */ - public int? pollFirst() + public int? popFirst() { - return poll(true); + return pop(true); } /* 队尾出队 */ - public int? pollLast() + public int? popLast() { - return poll(false); + return pop(false); } /* 访问队首元素 */ @@ -196,10 +196,10 @@ namespace hello_algo.chapter_stack_and_queue Console.WriteLine("元素 1 队首入队后 deque = " + string.Join(" ", deque.toArray())); /* 元素出队 */ - int? pollLast = deque.pollLast(); - Console.WriteLine("队尾出队元素 = " + pollLast + ",队尾出队后 deque = " + string.Join(" ", deque.toArray())); - int? pollFirst = deque.pollFirst(); - Console.WriteLine("队首出队元素 = " + pollFirst + ",队首出队后 deque = " + string.Join(" ", deque.toArray())); + int? popLast = deque.popLast(); + Console.WriteLine("队尾出队元素 = " + popLast + ",队尾出队后 deque = " + string.Join(" ", deque.toArray())); + int? popFirst = deque.popFirst(); + Console.WriteLine("队首出队元素 = " + popFirst + ",队首出队后 deque = " + string.Join(" ", deque.toArray())); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/csharp/chapter_stack_and_queue/linkedlist_queue.cs b/codes/csharp/chapter_stack_and_queue/linkedlist_queue.cs index 93141cbc4..138d7fa89 100644 --- a/codes/csharp/chapter_stack_and_queue/linkedlist_queue.cs +++ b/codes/csharp/chapter_stack_and_queue/linkedlist_queue.cs @@ -54,7 +54,7 @@ class LinkedListQueue } /* 出队 */ - public int poll() + public int pop() { int num = peek(); // 删除头结点 @@ -109,8 +109,8 @@ public class linkedlist_queue Console.WriteLine("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.poll(); - Console.WriteLine("出队元素 poll = " + poll + ",出队后 queue = " + String.Join(",", queue.toArray())); + int pop = queue.pop(); + Console.WriteLine("出队元素 pop = " + pop + ",出队后 queue = " + String.Join(",", queue.toArray())); /* 获取队列的长度 */ int size = queue.size(); diff --git a/codes/csharp/chapter_stack_and_queue/queue.cs b/codes/csharp/chapter_stack_and_queue/queue.cs index 4224daedc..c4fa36dc1 100644 --- a/codes/csharp/chapter_stack_and_queue/queue.cs +++ b/codes/csharp/chapter_stack_and_queue/queue.cs @@ -29,8 +29,8 @@ public class queue Console.WriteLine("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.Dequeue(); - Console.WriteLine("出队元素 poll = " + poll + ",出队后 queue = " + String.Join(",", queue.ToArray())); + int pop = queue.Dequeue(); + Console.WriteLine("出队元素 pop = " + pop + ",出队后 queue = " + String.Join(",", queue.ToArray())); /* 获取队列的长度 */ int size = queue.Count(); diff --git a/codes/go/chapter_stack_and_queue/array_queue.go b/codes/go/chapter_stack_and_queue/array_queue.go index f72402767..e4f692e50 100644 --- a/codes/go/chapter_stack_and_queue/array_queue.go +++ b/codes/go/chapter_stack_and_queue/array_queue.go @@ -47,7 +47,7 @@ func (q *arrayQueue) push(num int) { } /* 出队 */ -func (q *arrayQueue) poll() any { +func (q *arrayQueue) pop() any { num := q.peek() // 队首指针向后移动一位,若越过尾部则返回到数组头部 q.front = (q.front + 1) % q.queCapacity diff --git a/codes/go/chapter_stack_and_queue/deque_test.go b/codes/go/chapter_stack_and_queue/deque_test.go index 4353a7787..8e51901ca 100644 --- a/codes/go/chapter_stack_and_queue/deque_test.go +++ b/codes/go/chapter_stack_and_queue/deque_test.go @@ -112,11 +112,11 @@ func TestLinkedListDeque(t *testing.T) { fmt.Println("队尾元素 rear =", rear) // 元素出队 - pollFirst := deque.pollFirst() - fmt.Print("队首出队元素 pollFirst = ", pollFirst, ",队首出队后 deque = ") + popFirst := deque.popFirst() + fmt.Print("队首出队元素 popFirst = ", popFirst, ",队首出队后 deque = ") PrintList(deque.toList()) - pollLast := deque.pollLast() - fmt.Print("队尾出队元素 pollLast = ", pollLast, ",队尾出队后 deque = ") + popLast := deque.popLast() + fmt.Print("队尾出队元素 popLast = ", popLast, ",队尾出队后 deque = ") PrintList(deque.toList()) // 获取队的长度 @@ -136,6 +136,6 @@ func BenchmarkLinkedListDeque(b *testing.B) { deque.pushLast(777) } for i := 0; i < b.N; i++ { - deque.pollFirst() + deque.popFirst() } } diff --git a/codes/go/chapter_stack_and_queue/linkedlist_deque.go b/codes/go/chapter_stack_and_queue/linkedlist_deque.go index 31b5bbb56..b1f21b849 100644 --- a/codes/go/chapter_stack_and_queue/linkedlist_deque.go +++ b/codes/go/chapter_stack_and_queue/linkedlist_deque.go @@ -32,7 +32,7 @@ func (s *linkedListDeque) pushLast(value any) { } /* 队首元素出队 */ -func (s *linkedListDeque) pollFirst() any { +func (s *linkedListDeque) popFirst() any { if s.isEmpty() { return nil } @@ -42,7 +42,7 @@ func (s *linkedListDeque) pollFirst() any { } /* 队尾元素出队 */ -func (s *linkedListDeque) pollLast() any { +func (s *linkedListDeque) popLast() any { if s.isEmpty() { return nil } diff --git a/codes/go/chapter_stack_and_queue/linkedlist_queue.go b/codes/go/chapter_stack_and_queue/linkedlist_queue.go index ecb732aea..7044d8217 100644 --- a/codes/go/chapter_stack_and_queue/linkedlist_queue.go +++ b/codes/go/chapter_stack_and_queue/linkedlist_queue.go @@ -27,7 +27,7 @@ func (s *linkedListQueue) push(value any) { } /* 出队 */ -func (s *linkedListQueue) poll() any { +func (s *linkedListQueue) pop() any { if s.isEmpty() { return nil } diff --git a/codes/go/chapter_stack_and_queue/queue_test.go b/codes/go/chapter_stack_and_queue/queue_test.go index c9dfa2d75..cf46cd17b 100644 --- a/codes/go/chapter_stack_and_queue/queue_test.go +++ b/codes/go/chapter_stack_and_queue/queue_test.go @@ -31,9 +31,9 @@ func TestQueue(t *testing.T) { fmt.Println("队首元素 peek =", peek.Value) /* 元素出队 */ - poll := queue.Front() - queue.Remove(poll) - fmt.Print("出队元素 poll = ", poll.Value, ",出队后 queue = ") + pop := queue.Front() + queue.Remove(pop) + fmt.Print("出队元素 pop = ", pop.Value, ",出队后 queue = ") PrintList(queue) /* 获取队列的长度 */ @@ -64,8 +64,8 @@ func TestArrayQueue(t *testing.T) { fmt.Println("队首元素 peek =", peek) // 元素出队 - poll := queue.poll() - fmt.Print("出队元素 poll = ", poll, ", 出队后 queue = ") + pop := queue.pop() + fmt.Print("出队元素 pop = ", pop, ", 出队后 queue = ") PrintSlice(queue.toSlice()) // 获取队的长度 @@ -79,7 +79,7 @@ func TestArrayQueue(t *testing.T) { /* 测试环形数组 */ for i := 0; i < 10; i++ { queue.push(i) - queue.poll() + queue.pop() fmt.Print("第", i, "轮入队 + 出队后 queue =") PrintSlice(queue.toSlice()) } @@ -103,8 +103,8 @@ func TestLinkedListQueue(t *testing.T) { fmt.Println("队首元素 peek =", peek) // 元素出队 - poll := queue.poll() - fmt.Print("出队元素 poll = ", poll, ", 出队后 queue = ") + pop := queue.pop() + fmt.Print("出队元素 pop = ", pop, ", 出队后 queue = ") PrintList(queue.toList()) // 获取队的长度 @@ -125,7 +125,7 @@ func BenchmarkArrayQueue(b *testing.B) { queue.push(777) } for i := 0; i < b.N; i++ { - queue.poll() + queue.pop() } } @@ -137,6 +137,6 @@ func BenchmarkLinkedQueue(b *testing.B) { queue.push(777) } for i := 0; i < b.N; i++ { - queue.poll() + queue.pop() } } diff --git a/codes/java/chapter_stack_and_queue/array_deque.java b/codes/java/chapter_stack_and_queue/array_deque.java index 2d7552c4c..1c3aa4dec 100644 --- a/codes/java/chapter_stack_and_queue/array_deque.java +++ b/codes/java/chapter_stack_and_queue/array_deque.java @@ -71,7 +71,7 @@ class ArrayDeque { } /* 队首出队 */ - public int pollFirst() { + public int popFirst() { int num = peekFirst(); // 队首指针向后移动一位 front = index(front + 1); @@ -80,7 +80,7 @@ class ArrayDeque { } /* 队尾出队 */ - public int pollLast() { + public int popLast() { int num = peekLast(); queSize--; return num; @@ -135,10 +135,10 @@ public class array_deque { System.out.println("元素 1 队首入队后 deque = " + Arrays.toString(deque.toArray())); /* 元素出队 */ - int pollLast = deque.pollLast(); - System.out.println("队尾出队元素 = " + pollLast + ",队尾出队后 deque = " + Arrays.toString(deque.toArray())); - int pollFirst = deque.pollFirst(); - System.out.println("队首出队元素 = " + pollFirst + ",队首出队后 deque = " + Arrays.toString(deque.toArray())); + int popLast = deque.popLast(); + System.out.println("队尾出队元素 = " + popLast + ",队尾出队后 deque = " + Arrays.toString(deque.toArray())); + int popFirst = deque.popFirst(); + System.out.println("队首出队元素 = " + popFirst + ",队首出队后 deque = " + Arrays.toString(deque.toArray())); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/java/chapter_stack_and_queue/array_queue.java b/codes/java/chapter_stack_and_queue/array_queue.java index f3bd8b0eb..c7dd46b1d 100644 --- a/codes/java/chapter_stack_and_queue/array_queue.java +++ b/codes/java/chapter_stack_and_queue/array_queue.java @@ -49,7 +49,7 @@ class ArrayQueue { } /* 出队 */ - public int poll() { + public int pop() { int num = peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 front = (front + 1) % capacity(); @@ -94,8 +94,8 @@ public class array_queue { System.out.println("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.poll(); - System.out.println("出队元素 poll = " + poll + ",出队后 queue = " + Arrays.toString(queue.toArray())); + int pop = queue.pop(); + System.out.println("出队元素 pop = " + pop + ",出队后 queue = " + Arrays.toString(queue.toArray())); /* 获取队列的长度 */ int size = queue.size(); @@ -108,7 +108,7 @@ public class array_queue { /* 测试环形数组 */ for (int i = 0; i < 10; i++) { queue.push(i); - queue.poll(); + queue.pop(); System.out.println("第 " + i + " 轮入队 + 出队后 queue = " + Arrays.toString(queue.toArray())); } } diff --git a/codes/java/chapter_stack_and_queue/deque.java b/codes/java/chapter_stack_and_queue/deque.java index 56b73d346..9242ca005 100644 --- a/codes/java/chapter_stack_and_queue/deque.java +++ b/codes/java/chapter_stack_and_queue/deque.java @@ -30,10 +30,10 @@ public class deque { System.out.println("元素 1 队首入队后 deque = " + deque); /* 元素出队 */ - int pollLast = deque.pollLast(); - System.out.println("队尾出队元素 = " + pollLast + ",队尾出队后 deque = " + deque); - int pollFirst = deque.pollFirst(); - System.out.println("队首出队元素 = " + pollFirst + ",队首出队后 deque = " + deque); + int popLast = deque.pollLast(); + System.out.println("队尾出队元素 = " + popLast + ",队尾出队后 deque = " + deque); + int popFirst = deque.pollFirst(); + System.out.println("队首出队元素 = " + popFirst + ",队首出队后 deque = " + deque); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/java/chapter_stack_and_queue/linkedlist_deque.java b/codes/java/chapter_stack_and_queue/linkedlist_deque.java index afe5c0334..45dff8e95 100644 --- a/codes/java/chapter_stack_and_queue/linkedlist_deque.java +++ b/codes/java/chapter_stack_and_queue/linkedlist_deque.java @@ -71,7 +71,7 @@ class LinkedListDeque { } /* 出队操作 */ - private Integer poll(boolean isFront) { + private Integer pop(boolean isFront) { // 若队列为空,直接返回 null if (isEmpty()) return null; @@ -102,13 +102,13 @@ class LinkedListDeque { } /* 队首出队 */ - public Integer pollFirst() { - return poll(true); + public Integer popFirst() { + return pop(true); } /* 队尾出队 */ - public Integer pollLast() { - return poll(false); + public Integer popLast() { + return pop(false); } /* 访问队首元素 */ @@ -155,10 +155,10 @@ public class linkedlist_deque { System.out.println("元素 1 队首入队后 deque = " + Arrays.toString(deque.toArray())); /* 元素出队 */ - int pollLast = deque.pollLast(); - System.out.println("队尾出队元素 = " + pollLast + ",队尾出队后 deque = " + Arrays.toString(deque.toArray())); - int pollFirst = deque.pollFirst(); - System.out.println("队首出队元素 = " + pollFirst + ",队首出队后 deque = " + Arrays.toString(deque.toArray())); + int popLast = deque.popLast(); + System.out.println("队尾出队元素 = " + popLast + ",队尾出队后 deque = " + Arrays.toString(deque.toArray())); + int popFirst = deque.popFirst(); + System.out.println("队首出队元素 = " + popFirst + ",队首出队后 deque = " + Arrays.toString(deque.toArray())); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/java/chapter_stack_and_queue/linkedlist_queue.java b/codes/java/chapter_stack_and_queue/linkedlist_queue.java index e7ac6a49c..5dacaa3d4 100644 --- a/codes/java/chapter_stack_and_queue/linkedlist_queue.java +++ b/codes/java/chapter_stack_and_queue/linkedlist_queue.java @@ -45,7 +45,7 @@ class LinkedListQueue { } /* 出队 */ - public int poll() { + public int pop() { int num = peek(); // 删除头结点 front = front.next; @@ -90,8 +90,8 @@ public class linkedlist_queue { System.out.println("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.poll(); - System.out.println("出队元素 poll = " + poll + ",出队后 queue = " + Arrays.toString(queue.toArray())); + int pop = queue.pop(); + System.out.println("出队元素 pop = " + pop + ",出队后 queue = " + Arrays.toString(queue.toArray())); /* 获取队列的长度 */ int size = queue.size(); diff --git a/codes/java/chapter_stack_and_queue/queue.java b/codes/java/chapter_stack_and_queue/queue.java index 25457fbdb..baaf96603 100644 --- a/codes/java/chapter_stack_and_queue/queue.java +++ b/codes/java/chapter_stack_and_queue/queue.java @@ -26,8 +26,8 @@ public class queue { System.out.println("队首元素 peek = " + peek); /* 元素出队 */ - int poll = queue.poll(); - System.out.println("出队元素 poll = " + poll + ",出队后 queue = " + queue); + int pop = queue.poll(); + System.out.println("出队元素 pop = " + pop + ",出队后 queue = " + queue); /* 获取队列的长度 */ int size = queue.size(); diff --git a/codes/javascript/chapter_stack_and_queue/array_deque.js b/codes/javascript/chapter_stack_and_queue/array_deque.js index c7adc8548..4ae0c2524 100644 --- a/codes/javascript/chapter_stack_and_queue/array_deque.js +++ b/codes/javascript/chapter_stack_and_queue/array_deque.js @@ -68,7 +68,7 @@ class ArrayDeque { } /* 队首出队 */ - pollFirst() { + popFirst() { const num = this.peekFirst(); // 队首指针向后移动一位 this.#front = this.index(this.#front + 1); @@ -77,7 +77,7 @@ class ArrayDeque { } /* 队尾出队 */ - pollLast() { + popLast() { const num = this.peekLast(); this.#queSize--; return num; @@ -132,10 +132,10 @@ deque.pushFirst(1); console.log("元素 1 队首入队后 deque = [" + deque.toArray() + "]"); /* 元素出队 */ -const pollLast = deque.pollLast(); -console.log("队尾出队元素 = " + pollLast + ",队尾出队后 deque = [" + deque.toArray() + "]"); -const pollFirst = deque.pollFirst(); -console.log("队首出队元素 = " + pollFirst + ",队首出队后 deque = [" + deque.toArray()+ "]"); +const popLast = deque.popLast(); +console.log("队尾出队元素 = " + popLast + ",队尾出队后 deque = [" + deque.toArray() + "]"); +const popFirst = deque.popFirst(); +console.log("队首出队元素 = " + popFirst + ",队首出队后 deque = [" + deque.toArray()+ "]"); /* 获取双向队列的长度 */ const size = deque.size(); diff --git a/codes/javascript/chapter_stack_and_queue/array_queue.js b/codes/javascript/chapter_stack_and_queue/array_queue.js index 35584f282..399d87bf0 100644 --- a/codes/javascript/chapter_stack_and_queue/array_queue.js +++ b/codes/javascript/chapter_stack_and_queue/array_queue.js @@ -44,7 +44,7 @@ class ArrayQueue { } /* 出队 */ - poll() { + pop() { const num = this.peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 this.#front = (this.#front + 1) % this.capacity; @@ -89,8 +89,8 @@ const peek = queue.peek(); console.log("队首元素 peek = " + peek); /* 元素出队 */ -const poll = queue.poll(); -console.log("出队元素 poll = " + poll + ",出队后 queue =", queue.toArray()); +const pop = queue.pop(); +console.log("出队元素 pop = " + pop + ",出队后 queue =", queue.toArray()); /* 获取队列的长度 */ const size = queue.size; @@ -103,6 +103,6 @@ console.log("队列是否为空 = " + empty); /* 测试环形数组 */ for (let i = 0; i < 10; i++) { queue.push(i); - queue.poll(); + queue.pop(); console.log("第 " + i + " 轮入队 + 出队后 queue =", queue.toArray()); } diff --git a/codes/javascript/chapter_stack_and_queue/linkedlist_deque.js b/codes/javascript/chapter_stack_and_queue/linkedlist_deque.js index d5df1358d..bd9eb4eaf 100644 --- a/codes/javascript/chapter_stack_and_queue/linkedlist_deque.js +++ b/codes/javascript/chapter_stack_and_queue/linkedlist_deque.js @@ -62,7 +62,7 @@ class LinkedListDeque { } /* 队尾出队操作 */ - pollLast() { + popLast() { if (this.#queSize === 0) { return null; } @@ -79,7 +79,7 @@ class LinkedListDeque { } /* 队首出队操作 */ - pollFirst() { + popFirst() { if (this.#queSize === 0) { return null; } @@ -151,11 +151,11 @@ console.log("元素 1 队首入队后 linkedListDeque = "); linkedListDeque.print(); /* 元素出队 */ -const pollLast = linkedListDeque.pollLast(); -console.log("队尾出队元素 = " + pollLast + ",队尾出队后 linkedListDeque = "); +const popLast = linkedListDeque.popLast(); +console.log("队尾出队元素 = " + popLast + ",队尾出队后 linkedListDeque = "); linkedListDeque.print(); -const pollFirst = linkedListDeque.pollFirst(); -console.log("队首出队元素 = " + pollFirst + ",队首出队后 linkedListDeque = "); +const popFirst = linkedListDeque.popFirst(); +console.log("队首出队元素 = " + popFirst + ",队首出队后 linkedListDeque = "); linkedListDeque.print(); /* 获取双向队列的长度 */ diff --git a/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js b/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js index e0d015a41..71634c9b5 100644 --- a/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js +++ b/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js @@ -44,7 +44,7 @@ class LinkedListQueue { } /* 出队 */ - poll() { + pop() { const num = this.peek(); // 删除头结点 this.#front = this.#front.next; @@ -90,8 +90,8 @@ const peek = queue.peek(); console.log("队首元素 peek = " + peek); /* 元素出队 */ -const poll = queue.poll(); -console.log("出队元素 poll = " + poll + ",出队后 queue = " + queue.toArray()); +const pop = queue.pop(); +console.log("出队元素 pop = " + pop + ",出队后 queue = " + queue.toArray()); /* 获取队列的长度 */ const size = queue.size; diff --git a/codes/javascript/chapter_stack_and_queue/queue.js b/codes/javascript/chapter_stack_and_queue/queue.js index 7b20278b1..50e0a0296 100644 --- a/codes/javascript/chapter_stack_and_queue/queue.js +++ b/codes/javascript/chapter_stack_and_queue/queue.js @@ -23,8 +23,8 @@ console.log("队首元素 peek =", peek); /* 元素出队 */ // 底层是数组,因此 shift() 方法的时间复杂度为 O(n) -const poll = queue.shift(); -console.log("出队元素 poll =", poll, ",出队后 queue = ", queue); +const pop = queue.shift(); +console.log("出队元素 pop =", pop, ",出队后 queue = ", queue); /* 获取队列的长度 */ const size = queue.length; diff --git a/codes/python/chapter_stack_and_queue/array_deque.py b/codes/python/chapter_stack_and_queue/array_deque.py index f7383976f..df7cffe7c 100644 --- a/codes/python/chapter_stack_and_queue/array_deque.py +++ b/codes/python/chapter_stack_and_queue/array_deque.py @@ -60,7 +60,7 @@ class ArrayDeque: self.__nums[rear] = num self.__size += 1 - def poll_first(self) -> int: + def pop_first(self) -> int: """ 队首出队 """ num = self.peek_first() # 队首指针向后移动一位 @@ -68,7 +68,7 @@ class ArrayDeque: self.__size -= 1 return num - def poll_last(self) -> int: + def pop_last(self) -> int: """ 队尾出队 """ num = self.peek_last() self.__size -= 1 @@ -117,10 +117,10 @@ if __name__ == "__main__": print("元素 1 队首入队后 deque =", deque.to_array()) """ 元素出队 """ - poll_last: int = deque.poll_last() - print("队尾出队元素 =", poll_last, ",队尾出队后 deque =", deque.to_array()) - poll_first: int = deque.poll_first() - print("队首出队元素 =", poll_first, ",队首出队后 deque =", deque.to_array()) + pop_last: int = deque.pop_last() + print("队尾出队元素 =", pop_last, ",队尾出队后 deque =", deque.to_array()) + pop_first: int = deque.pop_first() + print("队首出队元素 =", pop_first, ",队首出队后 deque =", deque.to_array()) """ 获取双向队列的长度 """ size: int = deque.size() diff --git a/codes/python/chapter_stack_and_queue/array_queue.py b/codes/python/chapter_stack_and_queue/array_queue.py index 02d877768..788a71a4b 100644 --- a/codes/python/chapter_stack_and_queue/array_queue.py +++ b/codes/python/chapter_stack_and_queue/array_queue.py @@ -38,7 +38,7 @@ class ArrayQueue: self.__nums[rear] = num self.__size += 1 - def poll(self) -> int: + def pop(self) -> int: """ 出队 """ num: int = self.peek() # 队首指针向后移动一位,若越过尾部则返回到数组头部 @@ -79,8 +79,8 @@ if __name__ == "__main__": print("队首元素 peek =", peek) """ 元素出队 """ - poll: int = queue.poll() - print("出队元素 poll =", poll) + pop: int = queue.pop() + print("出队元素 pop =", pop) print("出队后 queue =", queue.to_list()) """ 获取队列的长度 """ @@ -94,5 +94,5 @@ if __name__ == "__main__": """ 测试环形数组 """ for i in range(10): queue.push(i) - queue.poll() + queue.pop() print("第", i, "轮入队 + 出队后 queue = ", queue.to_list()) diff --git a/codes/python/chapter_stack_and_queue/linkedlist_deque.py b/codes/python/chapter_stack_and_queue/linkedlist_deque.py index da649888a..a6d7c1f12 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_deque.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_deque.py @@ -60,7 +60,7 @@ class LinkedListDeque: """ 队尾入队 """ self.push(num, False) - def poll(self, is_front: bool) -> int: + def pop(self, is_front: bool) -> int: """ 出队操作 """ # 若队列为空,直接返回 None if self.is_empty(): @@ -86,13 +86,13 @@ class LinkedListDeque: self.__size -= 1 # 更新队列长度 return val - def poll_first(self) -> int: + def pop_first(self) -> int: """ 队首出队 """ - return self.poll(True) + return self.pop(True) - def poll_last(self) -> int: + def pop_last(self) -> int: """ 队尾出队 """ - return self.poll(False) + return self.pop(False) def peek_first(self) -> int: """ 访问队首元素 """ @@ -134,10 +134,10 @@ if __name__ == "__main__": print("元素 1 队首入队后 deque =", deque.to_array()) """ 元素出队 """ - poll_last: int = deque.poll_last() - print("队尾出队元素 =", poll_last, ",队尾出队后 deque =", deque.to_array()) - poll_first: int = deque.poll_first() - print("队首出队元素 =", poll_first, ",队首出队后 deque =", deque.to_array()) + pop_last: int = deque.pop_last() + print("队尾出队元素 =", pop_last, ",队尾出队后 deque =", deque.to_array()) + pop_first: int = deque.pop_first() + print("队首出队元素 =", pop_first, ",队首出队后 deque =", deque.to_array()) """ 获取双向队列的长度 """ size: int = deque.size() diff --git a/codes/python/chapter_stack_and_queue/linkedlist_queue.py b/codes/python/chapter_stack_and_queue/linkedlist_queue.py index 929122a05..50f9a431d 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_queue.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_queue.py @@ -38,7 +38,7 @@ class LinkedListQueue: self.__rear = node self.__size += 1 - def poll(self) -> int: + def pop(self) -> int: """ 出队 """ num = self.peek() # 删除头结点 @@ -81,8 +81,8 @@ if __name__ == "__main__": print("队首元素 front =", peek) """ 元素出队 """ - pop_front: int = queue.poll() - print("出队元素 poll =", pop_front) + pop_front: int = queue.pop() + print("出队元素 pop =", pop_front) print("出队后 queue =", queue.to_list()) """ 获取队列的长度 """ diff --git a/codes/rust/chapter_stack_and_queue/array_queue.rs b/codes/rust/chapter_stack_and_queue/array_queue.rs index 87b958dfd..8197b64d0 100644 --- a/codes/rust/chapter_stack_and_queue/array_queue.rs +++ b/codes/rust/chapter_stack_and_queue/array_queue.rs @@ -36,7 +36,7 @@ impl ArrayQueue { self.que_size += 1; } - fn poll(&mut self) -> i32 { + fn pop(&mut self) -> i32 { let num = self.peek(); self.front = (self.front + 1) % self.que_capacity; self.que_size -= 1; @@ -77,10 +77,10 @@ fn main() { let peek = queue.peek(); println!("队首元素 peek = {}", peek); - let poll = queue.poll(); + let pop = queue.pop(); println!( - "出队元素 poll = {:?},出队后 queue = {:?}", - poll, + "出队元素 pop = {:?},出队后 queue = {:?}", + pop, queue.to_vector() ); @@ -92,7 +92,7 @@ fn main() { for i in 0..10 { queue.push(i); - queue.poll(); + queue.pop(); println!("第 {:?} 轮入队 + 出队后 queue = {:?}", i, queue.to_vector()); } } diff --git a/codes/rust/chapter_stack_and_queue/deque.rs b/codes/rust/chapter_stack_and_queue/deque.rs index 3bc6f5fbc..7c6c30d77 100644 --- a/codes/rust/chapter_stack_and_queue/deque.rs +++ b/codes/rust/chapter_stack_and_queue/deque.rs @@ -27,11 +27,11 @@ pub fn main() { print!("\n队尾元素 peekLast = {peek_last}"); // 元素出队 - let poll_first = deque.pop_front().unwrap(); // 队首元素出队 - print!("\n队首出队元素 pollFirst = {poll_first},队首出队后 deque = "); + let pop_first = deque.pop_front().unwrap(); // 队首元素出队 + print!("\n队首出队元素 popFirst = {pop_first},队首出队后 deque = "); print_util::print_queue(&deque); - let poll_last = deque.pop_back().unwrap(); // 队尾元素出队 - print!("\n队尾出队元素 pollLast = {poll_last},队尾出队后 deque = "); + let pop_last = deque.pop_back().unwrap(); // 队尾元素出队 + print!("\n队尾出队元素 popLast = {pop_last},队尾出队后 deque = "); print_util::print_queue(&deque); // 获取双向队列的长度 diff --git a/codes/rust/chapter_stack_and_queue/queue.rs b/codes/rust/chapter_stack_and_queue/queue.rs index bc25cb36e..dfe708b57 100644 --- a/codes/rust/chapter_stack_and_queue/queue.rs +++ b/codes/rust/chapter_stack_and_queue/queue.rs @@ -27,8 +27,8 @@ pub fn main() { println!("\n队首元素 peek = {peek}"); // 元素出队 - let poll = queue.pop_front().unwrap(); - print!("出队元素 poll = {poll},出队后 queue = "); + let pop = queue.pop_front().unwrap(); + print!("出队元素 pop = {pop},出队后 queue = "); print_util::print_queue(&queue); // 获取队列的长度 diff --git a/codes/swift/chapter_stack_and_queue/array_deque.swift b/codes/swift/chapter_stack_and_queue/array_deque.swift index 8c291bf43..20254b873 100644 --- a/codes/swift/chapter_stack_and_queue/array_deque.swift +++ b/codes/swift/chapter_stack_and_queue/array_deque.swift @@ -68,7 +68,7 @@ class ArrayDeque { } /* 队首出队 */ - func pollFirst() -> Int { + func popFirst() -> Int { let num = peekFirst() // 队首指针向后移动一位 front = index(i: front + 1) @@ -77,7 +77,7 @@ class ArrayDeque { } /* 队尾出队 */ - func pollLast() -> Int { + func popLast() -> Int { let num = peekLast() queSize -= 1 return num @@ -136,10 +136,10 @@ enum _ArrayDeque { print("元素 1 队首入队后 deque = \(deque.toArray())") /* 元素出队 */ - let pollLast = deque.pollLast() - print("队尾出队元素 = \(pollLast),队尾出队后 deque = \(deque.toArray())") - let pollFirst = deque.pollFirst() - print("队首出队元素 = \(pollFirst),队首出队后 deque = \(deque.toArray())") + let popLast = deque.popLast() + print("队尾出队元素 = \(popLast),队尾出队后 deque = \(deque.toArray())") + let popFirst = deque.popFirst() + print("队首出队元素 = \(popFirst),队首出队后 deque = \(deque.toArray())") /* 获取双向队列的长度 */ let size = deque.size() diff --git a/codes/swift/chapter_stack_and_queue/array_queue.swift b/codes/swift/chapter_stack_and_queue/array_queue.swift index 0d39687a3..a7c2b439d 100644 --- a/codes/swift/chapter_stack_and_queue/array_queue.swift +++ b/codes/swift/chapter_stack_and_queue/array_queue.swift @@ -46,7 +46,7 @@ class ArrayQueue { /* 出队 */ @discardableResult - func poll() -> Int { + func pop() -> Int { let num = peek() // 队首指针向后移动一位,若越过尾部则返回到数组头部 front = (front + 1) % capacity() @@ -94,8 +94,8 @@ enum _ArrayQueue { print("队首元素 peek = \(peek)") /* 元素出队 */ - let poll = queue.poll() - print("出队元素 poll = \(poll),出队后 queue = \(queue.toArray())") + let pop = queue.pop() + print("出队元素 pop = \(pop),出队后 queue = \(queue.toArray())") /* 获取队列的长度 */ let size = queue.size() @@ -108,7 +108,7 @@ enum _ArrayQueue { /* 测试环形数组 */ for i in 0 ..< 10 { queue.push(num: i) - queue.poll() + queue.pop() print("第 \(i) 轮入队 + 出队后 queue = \(queue.toArray())") } } diff --git a/codes/swift/chapter_stack_and_queue/deque.swift b/codes/swift/chapter_stack_and_queue/deque.swift index 6638eacb3..8245caf55 100644 --- a/codes/swift/chapter_stack_and_queue/deque.swift +++ b/codes/swift/chapter_stack_and_queue/deque.swift @@ -27,11 +27,11 @@ enum Deque { print("队尾元素 peekLast = \(peekLast)") /* 元素出队 */ - // 使用 Array 模拟时 pollFirst 的复杂度为 O(n) - let pollFirst = deque.removeFirst() - print("队首出队元素 pollFirst = \(pollFirst),队首出队后 deque = \(deque)") - let pollLast = deque.removeLast() - print("队尾出队元素 pollLast = \(pollLast),队尾出队后 deque = \(deque)") + // 使用 Array 模拟时 popFirst 的复杂度为 O(n) + let popFirst = deque.removeFirst() + print("队首出队元素 popFirst = \(popFirst),队首出队后 deque = \(deque)") + let popLast = deque.removeLast() + print("队尾出队元素 popLast = \(popLast),队尾出队后 deque = \(deque)") /* 获取双向队列的长度 */ let size = deque.count diff --git a/codes/swift/chapter_stack_and_queue/linkedlist_deque.swift b/codes/swift/chapter_stack_and_queue/linkedlist_deque.swift index b1ae7806f..2a2905e36 100644 --- a/codes/swift/chapter_stack_and_queue/linkedlist_deque.swift +++ b/codes/swift/chapter_stack_and_queue/linkedlist_deque.swift @@ -71,7 +71,7 @@ class LinkedListDeque { } /* 出队操作 */ - private func poll(isFront: Bool) -> Int { + private func pop(isFront: Bool) -> Int { if isEmpty() { fatalError("双向队列为空") } @@ -103,13 +103,13 @@ class LinkedListDeque { } /* 队首出队 */ - func pollFirst() -> Int { - poll(isFront: true) + func popFirst() -> Int { + pop(isFront: true) } /* 队尾出队 */ - func pollLast() -> Int { - poll(isFront: false) + func popLast() -> Int { + pop(isFront: false) } /* 访问队首元素 */ @@ -158,10 +158,10 @@ enum _LinkedListDeque { print("元素 1 队首入队后 deque = \(deque.toArray())") /* 元素出队 */ - let pollLast = deque.pollLast() - print("队尾出队元素 = \(pollLast),队尾出队后 deque = \(deque.toArray())") - let pollFirst = deque.pollFirst() - print("队首出队元素 = \(pollFirst),队首出队后 deque = \(deque.toArray())") + let popLast = deque.popLast() + print("队尾出队元素 = \(popLast),队尾出队后 deque = \(deque.toArray())") + let popFirst = deque.popFirst() + print("队首出队元素 = \(popFirst),队首出队后 deque = \(deque.toArray())") /* 获取双向队列的长度 */ let size = deque.size() diff --git a/codes/swift/chapter_stack_and_queue/linkedlist_queue.swift b/codes/swift/chapter_stack_and_queue/linkedlist_queue.swift index bc2d5231b..3c85acca2 100644 --- a/codes/swift/chapter_stack_and_queue/linkedlist_queue.swift +++ b/codes/swift/chapter_stack_and_queue/linkedlist_queue.swift @@ -43,7 +43,7 @@ class LinkedListQueue { /* 出队 */ @discardableResult - func poll() -> Int { + func pop() -> Int { let num = peek() // 删除头结点 front = front?.next @@ -91,8 +91,8 @@ enum _LinkedListQueue { print("队首元素 peek = \(peek)") /* 元素出队 */ - let poll = queue.poll() - print("出队元素 poll = \(poll),出队后 queue = \(queue.toArray())") + let pop = queue.pop() + print("出队元素 pop = \(pop),出队后 queue = \(queue.toArray())") /* 获取队列的长度 */ let size = queue.size() diff --git a/codes/swift/chapter_stack_and_queue/queue.swift b/codes/swift/chapter_stack_and_queue/queue.swift index ea1e94722..e7b746e35 100644 --- a/codes/swift/chapter_stack_and_queue/queue.swift +++ b/codes/swift/chapter_stack_and_queue/queue.swift @@ -25,9 +25,9 @@ enum Queue { print("队首元素 peek = \(peek)") /* 元素出队 */ - // 使用 Array 模拟时 poll 的复杂度为 O(n) + // 使用 Array 模拟时 pop 的复杂度为 O(n) let pool = queue.removeFirst() - print("出队元素 poll = \(pool),出队后 queue = \(queue)") + print("出队元素 pop = \(pool),出队后 queue = \(queue)") /* 获取队列的长度 */ let size = queue.count diff --git a/codes/typescript/chapter_stack_and_queue/array_deque.ts b/codes/typescript/chapter_stack_and_queue/array_deque.ts index 43f5e7640..0cca72036 100644 --- a/codes/typescript/chapter_stack_and_queue/array_deque.ts +++ b/codes/typescript/chapter_stack_and_queue/array_deque.ts @@ -69,7 +69,7 @@ class ArrayDeque { } /* 队首出队 */ - pollFirst(): number { + popFirst(): number { const num: number = this.peekFirst(); // 队首指针向后移动一位 this.front = this.index(this.front + 1); @@ -78,7 +78,7 @@ class ArrayDeque { } /* 队尾出队 */ - pollLast(): number { + popLast(): number { const num: number = this.peekLast(); this.queSize--; return num; @@ -133,10 +133,10 @@ deque.pushFirst(1); console.log("元素 1 队首入队后 deque = [" + deque.toArray() + "]"); /* 元素出队 */ -const pollLast = deque.pollLast(); -console.log("队尾出队元素 = " + pollLast + ",队尾出队后 deque = [" + deque.toArray() + "]"); -const pollFirst = deque.pollFirst(); -console.log("队首出队元素 = " + pollFirst + ",队首出队后 deque = [" + deque.toArray()+ "]"); +const popLast = deque.popLast(); +console.log("队尾出队元素 = " + popLast + ",队尾出队后 deque = [" + deque.toArray() + "]"); +const popFirst = deque.popFirst(); +console.log("队首出队元素 = " + popFirst + ",队首出队后 deque = [" + deque.toArray()+ "]"); /* 获取双向队列的长度 */ const size = deque.size(); diff --git a/codes/typescript/chapter_stack_and_queue/array_queue.ts b/codes/typescript/chapter_stack_and_queue/array_queue.ts index 775965567..77a625029 100644 --- a/codes/typescript/chapter_stack_and_queue/array_queue.ts +++ b/codes/typescript/chapter_stack_and_queue/array_queue.ts @@ -45,7 +45,7 @@ class ArrayQueue { } /* 出队 */ - poll(): number { + pop(): number { const num = this.peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 this.front = (this.front + 1) % this.capacity; @@ -89,8 +89,8 @@ const peek = queue.peek(); console.log("队首元素 peek = " + peek); /* 元素出队 */ -const poll = queue.poll(); -console.log("出队元素 poll = " + poll + ",出队后 queue =", queue.toArray()); +const pop = queue.pop(); +console.log("出队元素 pop = " + pop + ",出队后 queue =", queue.toArray()); /* 获取队列的长度 */ const size = queue.size; @@ -103,7 +103,7 @@ console.log("队列是否为空 = " + empty); /* 测试环形数组 */ for (let i = 0; i < 10; i++) { queue.push(i); - queue.poll(); + queue.pop(); console.log("第 " + i + " 轮入队 + 出队后 queue =", queue.toArray()); } diff --git a/codes/typescript/chapter_stack_and_queue/linkedlist_deque.ts b/codes/typescript/chapter_stack_and_queue/linkedlist_deque.ts index 1eb6f3e81..6195d17a6 100644 --- a/codes/typescript/chapter_stack_and_queue/linkedlist_deque.ts +++ b/codes/typescript/chapter_stack_and_queue/linkedlist_deque.ts @@ -62,7 +62,7 @@ class LinkedListDeque { } /* 队尾出队操作 */ - pollLast(): number { + popLast(): number { if (this.queSize === 0) { return null; } @@ -79,7 +79,7 @@ class LinkedListDeque { } /* 队首出队操作 */ - pollFirst(): number { + popFirst(): number { if (this.queSize === 0) { return null; } @@ -151,11 +151,11 @@ console.log("元素 1 队首入队后 linkedListDeque = "); linkedListDeque.print(); /* 元素出队 */ -const pollLast: number = linkedListDeque.pollLast(); -console.log("队尾出队元素 = " + pollLast + ",队尾出队后 linkedListDeque = "); +const popLast: number = linkedListDeque.popLast(); +console.log("队尾出队元素 = " + popLast + ",队尾出队后 linkedListDeque = "); linkedListDeque.print(); -const pollFirst: number = linkedListDeque.pollFirst(); -console.log("队首出队元素 = " + pollFirst + ",队首出队后 linkedListDeque = "); +const popFirst: number = linkedListDeque.popFirst(); +console.log("队首出队元素 = " + popFirst + ",队首出队后 linkedListDeque = "); linkedListDeque.print(); /* 获取双向队列的长度 */ diff --git a/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts b/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts index b22905527..7aab5b469 100644 --- a/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts +++ b/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts @@ -44,7 +44,7 @@ class LinkedListQueue { } /* 出队 */ - poll(): number { + pop(): number { const num = this.peek(); if (!this.front) throw new Error('队列为空'); // 删除头结点 @@ -88,8 +88,8 @@ const peek = queue.peek(); console.log('队首元素 peek = ' + peek); /* 元素出队 */ -const poll = queue.poll(); -console.log('出队元素 poll = ' + poll + ',出队后 queue = ' + queue.toArray()); +const pop = queue.pop(); +console.log('出队元素 pop = ' + pop + ',出队后 queue = ' + queue.toArray()); /* 获取队列的长度 */ const size = queue.size; diff --git a/codes/typescript/chapter_stack_and_queue/queue.ts b/codes/typescript/chapter_stack_and_queue/queue.ts index 05123bf31..7c88bbbd4 100644 --- a/codes/typescript/chapter_stack_and_queue/queue.ts +++ b/codes/typescript/chapter_stack_and_queue/queue.ts @@ -23,8 +23,8 @@ console.log("队首元素 peek =", peek); /* 元素出队 */ // 底层是数组,因此 shift() 方法的时间复杂度为 O(n) -const poll = queue.shift(); -console.log("出队元素 poll =", poll, ",出队后 queue = ", queue); +const pop = queue.shift(); +console.log("出队元素 pop =", pop, ",出队后 queue = ", queue); /* 获取队列的长度 */ const size = queue.length; diff --git a/codes/zig/chapter_stack_and_queue/array_queue.zig b/codes/zig/chapter_stack_and_queue/array_queue.zig index 1ac5131b1..93be62ce6 100644 --- a/codes/zig/chapter_stack_and_queue/array_queue.zig +++ b/codes/zig/chapter_stack_and_queue/array_queue.zig @@ -64,7 +64,7 @@ pub fn ArrayQueue(comptime T: type) type { } // 出队 - pub fn poll(self: *Self) T { + pub fn pop(self: *Self) T { var num = self.peek(); // 队首指针向后移动一位,若越过尾部则返回到数组头部 self.front = (self.front + 1) % self.capacity(); @@ -115,8 +115,8 @@ pub fn main() !void { std.debug.print("\n队首元素 peek = {}", .{peek}); // 元素出队 - var poll = queue.poll(); - std.debug.print("\n出队元素 poll = {},出队后 queue = ", .{poll}); + var pop = queue.pop(); + std.debug.print("\n出队元素 pop = {},出队后 queue = ", .{pop}); inc.PrintUtil.printArray(i32, try queue.toArray()); // 获取队列的长度 @@ -131,7 +131,7 @@ pub fn main() !void { var i: i32 = 0; while (i < 10) : (i += 1) { try queue.push(i); - _ = queue.poll(); + _ = queue.pop(); std.debug.print("\n第 {} 轮入队 + 出队后 queue = ", .{i}); inc.PrintUtil.printArray(i32, try queue.toArray()); } diff --git a/codes/zig/chapter_stack_and_queue/deque.zig b/codes/zig/chapter_stack_and_queue/deque.zig index 0b4bd374a..aa9d1cc8b 100644 --- a/codes/zig/chapter_stack_and_queue/deque.zig +++ b/codes/zig/chapter_stack_and_queue/deque.zig @@ -32,11 +32,11 @@ pub fn main() !void { std.debug.print("\n队尾元素 peekLast = {}", .{peekLast}); // 元素出队 - var pollFirst = deque.popFirst().?.data; // 队首元素出队 - std.debug.print("\n队首出队元素 pollFirst = {},队首出队后 deque = ", .{pollFirst}); + var popFirst = deque.popFirst().?.data; // 队首元素出队 + std.debug.print("\n队首出队元素 popFirst = {},队首出队后 deque = ", .{popFirst}); inc.PrintUtil.printQueue(i32, deque); - var pollLast = deque.pop().?.data; // 队尾元素出队 - std.debug.print("\n队尾出队元素 pollLast = {},队尾出队后 deque = ", .{pollLast}); + var popLast = deque.pop().?.data; // 队尾元素出队 + std.debug.print("\n队尾出队元素 popLast = {},队尾出队后 deque = ", .{popLast}); inc.PrintUtil.printQueue(i32, deque); // 获取双向队列的长度 diff --git a/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig b/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig index 169a1d9e4..0c8bae726 100644 --- a/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig +++ b/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig @@ -96,7 +96,7 @@ pub fn LinkedListDeque(comptime T: type) type { } // 出队操作 - pub fn poll(self: *Self, is_front: bool) T { + pub fn pop(self: *Self, is_front: bool) T { if (self.isEmpty()) @panic("双向队列为空"); var val: T = undefined; // 队首出队操作 @@ -125,13 +125,13 @@ pub fn LinkedListDeque(comptime T: type) type { } // 队首出队 - pub fn pollFirst(self: *Self) T { - return self.poll(true); + pub fn popFirst(self: *Self) T { + return self.pop(true); } // 队尾出队 - pub fn pollLast(self: *Self) T { - return self.poll(false); + pub fn popLast(self: *Self) T { + return self.pop(false); } // 访问队首元素 @@ -188,11 +188,11 @@ pub fn main() !void { inc.PrintUtil.printArray(i32, try deque.toArray()); // 元素出队 - var poll_last = deque.pollLast(); - std.debug.print("\n队尾出队元素 = {},队尾出队后 deque = ", .{poll_last}); + var pop_last = deque.popLast(); + std.debug.print("\n队尾出队元素 = {},队尾出队后 deque = ", .{pop_last}); inc.PrintUtil.printArray(i32, try deque.toArray()); - var poll_first = deque.pollFirst(); - std.debug.print("\n队首出队元素 = {},队首出队后 deque = ", .{poll_first}); + var pop_first = deque.popFirst(); + std.debug.print("\n队首出队元素 = {},队首出队后 deque = ", .{pop_first}); inc.PrintUtil.printArray(i32, try deque.toArray()); // 获取双向队列的长度 diff --git a/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig b/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig index e9639d70d..78c922742 100644 --- a/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig +++ b/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig @@ -67,7 +67,7 @@ pub fn LinkedListQueue(comptime T: type) type { } // 出队 - pub fn poll(self: *Self) T { + pub fn pop(self: *Self) T { var num = self.peek(); // 删除头结点 self.front = self.front.?.next; @@ -111,8 +111,8 @@ pub fn main() !void { std.debug.print("\n队首元素 peek = {}", .{peek}); // 元素出队 - var poll = queue.poll(); - std.debug.print("\n出队元素 poll = {},出队后 queue = ", .{poll}); + var pop = queue.pop(); + std.debug.print("\n出队元素 pop = {},出队后 queue = ", .{pop}); inc.PrintUtil.printArray(i32, try queue.toArray()); // 获取队列的长度 diff --git a/codes/zig/chapter_stack_and_queue/queue.zig b/codes/zig/chapter_stack_and_queue/queue.zig index ce5b9c098..8a14fe810 100644 --- a/codes/zig/chapter_stack_and_queue/queue.zig +++ b/codes/zig/chapter_stack_and_queue/queue.zig @@ -30,8 +30,8 @@ pub fn main() !void { std.debug.print("\n队首元素 peek = {}", .{peek}); // 元素出队 - var poll = queue.popFirst().?.data; - std.debug.print("\n出队元素 poll = {},出队后 queue = ", .{poll}); + var pop = queue.popFirst().?.data; + std.debug.print("\n出队元素 pop = {},出队后 queue = ", .{pop}); inc.PrintUtil.printQueue(i32, queue); // 获取队列的长度 diff --git a/docs/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png b/docs/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png index 86c0653ad..192c855a5 100644 Binary files a/docs/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png and b/docs/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque.png b/docs/chapter_stack_and_queue/deque.assets/array_deque.png index 67c4f2c38..3ef1c2889 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/array_deque.png and b/docs/chapter_stack_and_queue/deque.assets/array_deque.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_first.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_first.png deleted file mode 100644 index 680013210..000000000 Binary files a/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_first.png and /dev/null differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_last.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_last.png deleted file mode 100644 index 552a955af..000000000 Binary files a/docs/chapter_stack_and_queue/deque.assets/array_deque_poll_last.png and /dev/null differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_first.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_first.png new file mode 100644 index 000000000..8137d0163 Binary files /dev/null and b/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_first.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_last.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_last.png new file mode 100644 index 000000000..7c759310f Binary files /dev/null and b/docs/chapter_stack_and_queue/deque.assets/array_deque_pop_last.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_push_first.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_push_first.png index 215486a58..04120335e 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/array_deque_push_first.png and b/docs/chapter_stack_and_queue/deque.assets/array_deque_push_first.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/array_deque_push_last.png b/docs/chapter_stack_and_queue/deque.assets/array_deque_push_last.png index 4d661323e..33816de8e 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/array_deque_push_last.png and b/docs/chapter_stack_and_queue/deque.assets/array_deque_push_last.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/deque_operations.png b/docs/chapter_stack_and_queue/deque.assets/deque_operations.png index 5c263a408..da8e03c07 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/deque_operations.png and b/docs/chapter_stack_and_queue/deque.assets/deque_operations.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque.png index 5e4fce6c3..407bd6205 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque.png and b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_first.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_first.png deleted file mode 100644 index 748ee9746..000000000 Binary files a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_first.png and /dev/null differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_last.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_last.png deleted file mode 100644 index 41fc03161..000000000 Binary files a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_poll_last.png and /dev/null differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_first.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_first.png new file mode 100644 index 000000000..22bb86308 Binary files /dev/null and b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_first.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_last.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_last.png new file mode 100644 index 000000000..f05b270fd Binary files /dev/null and b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_pop_last.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_first.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_first.png index 1eadb61e8..2f0d0e531 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_first.png and b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_first.png differ diff --git a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_last.png b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_last.png index 365cbcb57..811cb97c7 100644 Binary files a/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_last.png and b/docs/chapter_stack_and_queue/deque.assets/linkedlist_deque_push_last.png differ diff --git a/docs/chapter_stack_and_queue/deque.md b/docs/chapter_stack_and_queue/deque.md index 1920d8115..a26501ab4 100644 --- a/docs/chapter_stack_and_queue/deque.md +++ b/docs/chapter_stack_and_queue/deque.md @@ -6,18 +6,18 @@ ## 双向队列常用操作 -双向队列的常用操作见下表,方法名需根据语言来确定,此处以 Java 为例。 +双向队列的常用操作见下表,方法名需根据语言来确定。