Init
This commit is contained in:
38
node_modules/sweet-collections/dist/stack/Stack.js
generated
vendored
Normal file
38
node_modules/sweet-collections/dist/stack/Stack.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Stack = void 0;
|
||||
class Stack {
|
||||
constructor() {
|
||||
this._size = 0;
|
||||
}
|
||||
push(...values) {
|
||||
for (const value of values) {
|
||||
this.head = { value, next: this.head };
|
||||
this._size++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
pop(_default) {
|
||||
if (this.head) {
|
||||
const value = this.head.value;
|
||||
this.head = this.head.next;
|
||||
this._size--;
|
||||
return value;
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
top() {
|
||||
return this.head.value;
|
||||
}
|
||||
isEmpty() {
|
||||
return this.head === undefined;
|
||||
}
|
||||
clear() {
|
||||
this.head = undefined;
|
||||
this._size = 0;
|
||||
}
|
||||
get size() {
|
||||
return this._size;
|
||||
}
|
||||
}
|
||||
exports.Stack = Stack;
|
||||
Reference in New Issue
Block a user