Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created July 22, 2020 14:42
Show Gist options
  • Save AitorAlejandro/f8be80eb3e06ad94955e1d9a4888c5d0 to your computer and use it in GitHub Desktop.
Save AitorAlejandro/f8be80eb3e06ad94955e1d9a4888c5d0 to your computer and use it in GitHub Desktop.
Deque structure - array based
class Deque {
constructor() {
this.items = [];
}
addFront(item) {
this.items.unshift(item);
}
addBack(item) {
return this.items.push(item);
}
removeFront() {
return this.items.shift();
}
removeBack() {
return this.items.pop();
}
peekFront() {
return this.items[0];
}
peekBack() {
return this.items[this.items.length -1];
}
clear() {
this.items = [];
}
isEmpty() {
return this.items.length === 0;
}
size() {
return this.items.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment