typescript-ds-lib
Version:
A collection of TypeScript data structure implementations
76 lines • 1.92 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Deque = void 0;
const linked_list_1 = require("./linked-list");
const base_collection_1 = require("./base-collection");
class Deque extends base_collection_1.BaseCollection {
items;
constructor() {
super();
this.items = new linked_list_1.LinkedList();
}
/**
* Adds an element to the front of the deque
*/
pushFront(element) {
this.items.pushFront(element);
}
/**
* Adds an element to the back of the deque
*/
pushBack(element) {
this.items.pushBack(element);
}
/**
* Removes and returns the front element from the deque, or undefined if deque is empty
*/
popFront() {
return this.items.popFront();
}
/**
* Removes and returns the back element from the deque, or undefined if deque is empty
*/
popBack() {
return this.items.popBack();
}
/**
* Returns the front element without removing it, or undefined if deque is empty
*/
front() {
return this.items.get(0);
}
/**
* Returns the back element without removing it, or undefined if deque is empty
*/
back() {
return this.items.get(this.items.size() - 1);
}
/**
* Returns true if the deque is empty, false otherwise
*/
isEmpty() {
return this.items.isEmpty();
}
/**
* Returns the number of elements in the deque
*/
size() {
return this.items.size();
}
/**
* Removes all elements from the deque
*/
clear() {
this.items.clear();
}
/**
* Checks if two deques are equal.
*/
equals(other) {
if (!other || !(other instanceof Deque))
return false;
return this.items.equals(other.items);
}
}
exports.Deque = Deque;
//# sourceMappingURL=deque.js.map
;