mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
refactor: Replace poll with pop in Queue and Deque (#415)
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user