Add Queue.

This commit is contained in:
Oleksii Trekhleb
2018-03-28 15:53:12 +03:00
parent 55d6aa5758
commit c8bfe9ffaa
8 changed files with 4059 additions and 25 deletions

View File

@@ -0,0 +1,28 @@
import LinkedList from '../linked-list/LinkedList';
export default class Queue {
constructor() {
this.linkedList = new LinkedList();
}
isEmpty() {
return !this.linkedList.tail;
}
peek() {
if (!this.linkedList.tail) {
return null;
}
return this.linkedList.tail.value;
}
add(value) {
this.linkedList.append({ value });
}
remove() {
const removedTail = this.linkedList.deleteTail();
return removedTail ? removedTail.value : null;
}
}