MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / Queue

Class Queue

chapter04/util/Queue.js:4–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2var LinkedList = require('./LinkedList');
3
4class Queue {
5 constructor() {
6 this._list = new LinkedList();
7 }
8
9 enqueue(value) {
10 this._list.append(value);
11 }
12
13 dequeue() {
14 let node = this._list.popFirst();
15 return node.value;
16 }
17
18 peek() {
19 return this._list.head ? this._list.head.value : null;
20 }
21
22 isEmpty() {
23 return this._list.head == null;
24 }
25
26 _toArray() {
27 return this._list._toArray();
28 }
29}
30
31// alias
32Queue.prototype.add = Queue.prototype.enqueue;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected