Add Stack.

This commit is contained in:
Oleksii Trekhleb
2018-03-28 17:01:46 +03:00
parent 159d489e52
commit 8da6754523
9 changed files with 189 additions and 48 deletions

View File

@@ -10,19 +10,19 @@ export default class Queue {
}
peek() {
if (!this.linkedList.tail) {
if (!this.linkedList.head) {
return null;
}
return this.linkedList.tail.value;
return this.linkedList.head.value;
}
add(value) {
enqueue(value) {
this.linkedList.append({ value });
}
remove() {
const removedTail = this.linkedList.deleteTail();
return removedTail ? removedTail.value : null;
dequeue() {
const removedHead = this.linkedList.deleteHead();
return removedHead ? removedHead.value : null;
}
}