Replace poll with pop

This commit is contained in:
krahets
2023-03-13 22:39:45 +08:00
parent 28aacccf44
commit 516cb17775
6 changed files with 27 additions and 27 deletions

View File

@@ -70,7 +70,7 @@ func (q *arrayDeque) pushLast(num int) {
}
/* 队首出队 */
func (q *arrayDeque) pollFirst() any {
func (q *arrayDeque) popFirst() any {
num := q.peekFirst()
// 队首指针向后移动一位
q.front = q.index(q.front + 1)
@@ -79,7 +79,7 @@ func (q *arrayDeque) pollFirst() any {
}
/* 队尾出队 */
func (q *arrayDeque) pollLast() any {
func (q *arrayDeque) popLast() any {
num := q.peekLast()
q.queSize--
return num

View File

@@ -76,11 +76,11 @@ func TestArrayDeque(t *testing.T) {
PrintSlice(deque.toSlice())
/* 元素出队 */
pollFirst := deque.pollFirst()
fmt.Print("队首出队元素 pollFirst = ", pollFirst, ",队首出队后 deque = ")
popFirst := deque.popFirst()
fmt.Print("队首出队元素 popFirst = ", popFirst, ",队首出队后 deque = ")
PrintSlice(deque.toSlice())
pollLast := deque.pollLast()
fmt.Print("队尾出队元素 pollLast = ", pollLast, ",队尾出队后 deque = ")
popLast := deque.popLast()
fmt.Print("队尾出队元素 popLast = ", popLast, ",队尾出队后 deque = ")
PrintSlice(deque.toSlice())
/* 获取双向队列的长度 */