ShopAI-Extension/scripts/utils/common.js
2024-04-26 21:32:32 +08:00

41 lines
No EOL
659 B
JavaScript

// common.js provides the advanced data structures.
export class Queue {
#elements;
constructor() {
this.#elements = [];
}
enqueue(element) {
this.#elements.push(element);
}
dequeue() {
return this.#elements.shift();
}
isEmpty() {
return this.#elements.length <= 0;
}
}
export class Stack {
#elements;
constructor() {
this.#elements = [];
}
push(element) {
this.#elements.push(element);
}
pop() {
return this.#elements.pop();
}
isEmpty() {
return this.#elements.length <= 0;
}
}