1 | import LinkedList from "./LinkedList";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | class Queue {
|
7 | constructor() {
|
8 | this.linkedList = new LinkedList();
|
9 | }
|
10 |
|
11 | isEmpty() {
|
12 | return !this.linkedList.head;
|
13 | }
|
14 |
|
15 | peek() {
|
16 | if (!this.linkedList.head) {
|
17 | return null;
|
18 | }
|
19 | return this.linkedList.head.value;
|
20 | }
|
21 |
|
22 |
|
23 | enqueue() {
|
24 | this.linkedList.append(value);
|
25 | }
|
26 |
|
27 |
|
28 | dequeue() {
|
29 | const removed = this.linkedList.deleteHead();
|
30 | return removed ? removed.value : null;
|
31 | }
|
32 |
|
33 | toString(callback) {
|
34 | return this.linkedList.toString(callback);
|
35 | }
|
36 | }
|
37 |
|
38 | export default Queue;
|