Skip to content

Instantly share code, notes, and snippets.

@anotheremily
Created March 12, 2010 21:33
Show Gist options
  • Save anotheremily/330817 to your computer and use it in GitHub Desktop.
Save anotheremily/330817 to your computer and use it in GitHub Desktop.
function Stack() {
this.reset();
}
Stack.prototype.pop = function () {
if (this.empty() !== true) {
this.length -= 1;
return this.items.pop();
}
return undefined;
};
Stack.prototype.push = function (item) {
this.items.push(item);
this.length += 1;
return true;
};
Stack.prototype.empty = function () {
if (this.length === 0) {
return true;
}
return false;
};
Stack.prototype.reset = function () {
this.items = [];
this.length = 0;
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment