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