forked from trekhleb/javascript-algorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.js
More file actions
Latest commit
32 lines (25 loc) · 571 Bytes
/
Copy pathQueue.js
File metadata and controls
32 lines (25 loc) · 571 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importLinkedListfrom'../linked-list/LinkedList';
exportdefaultclassQueue{
constructor(){
this.linkedList=newLinkedList();
}
isEmpty(){
return!this.linkedList.tail;
}
peek(){
if(!this.linkedList.head){
returnnull;
}
returnthis.linkedList.head.value;
}
enqueue(value){
this.linkedList.append(value);
}
dequeue(){
constremovedHead=this.linkedList.deleteHead();
returnremovedHead ? removedHead.value : null;
}
toString(callback){
returnthis.linkedList.toString(callback);
}
}