| 2 | var LinkedList = require('./LinkedList'); |
| 3 | |
| 4 | class 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 |
| 32 | Queue.prototype.add = Queue.prototype.enqueue; |
nothing calls this directly
no outgoing calls
no test coverage detected