@selenite/graph-editor
Version:
A graph editor for visual programming, based on rete and svelte.
27 lines (26 loc) • 506 B
JavaScript
export class Stack {
stack; // Array of items
constructor() {
this.stack = [];
}
// Push an item
push(item) {
this.stack.push(item);
}
// Pop an item
pop() {
return this.stack.pop();
}
// Peek at the top item
peek() {
return this.stack.at(-1);
}
// Check if the stack is empty
isEmpty() {
return this.stack.length === 0;
}
// Get the stack length
size() {
return this.stack.length;
}
}