mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 22:34:18 +08:00
Update the chapter of stack and queue.
This commit is contained in:
@ -7,8 +7,7 @@
|
||||
|
||||
/* Driver Code */
|
||||
/* 初始化队列 */
|
||||
// JavaScript 没有内置的队列,可以把 Array 当作队列来使用
|
||||
// 注意:由于是数组,所以 shift() 的时间复杂度是 O(n)
|
||||
// JavaScript 没有内置的队列,可以把 Array 当作队列来使用
|
||||
const queue = [];
|
||||
|
||||
/* 元素入队 */
|
||||
@ -22,7 +21,7 @@ queue.push(4);
|
||||
const peek = queue[0];
|
||||
|
||||
/* 元素出队 */
|
||||
// shift() 方法的时间复杂度为 O(n)
|
||||
// 底层是数组,因此 shift() 方法的时间复杂度为 O(n)
|
||||
const poll = queue.shift();
|
||||
|
||||
/* 获取队列的长度 */
|
||||
|
Reference in New Issue
Block a user