Created
October 8, 2019 04:40
-
-
Save kingsleytan/4b580a03bc278e084a497164a14cf9c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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