Skip to content

Instantly share code, notes, and snippets.

@kingsleytan
Created October 8, 2019 04:40
Show Gist options
  • Save kingsleytan/4b580a03bc278e084a497164a14cf9c9 to your computer and use it in GitHub Desktop.
Save kingsleytan/4b580a03bc278e084a497164a14cf9c9 to your computer and use it in GitHub Desktop.
function Stack() {
this.count = 0;
this.storage = {};
this.push = function (value) {
this.storage[this.count] = value;
this.count++;
}
this.pop = function () {
if (this.count === 0) {
return undefined;
}
this.count--;
var result = this.storage[this.count];
delete this.storage[this.count];
return result;
}
this.peek = function () {
return this.storage[this.count - 1];
}
this.size = function () {
return this.count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment