Created
July 25, 2021 20:48
-
-
Save giovanisleite/d8410bfb031880787c797a1232b77850 to your computer and use it in GitHub Desktop.
Data Structure: Stack
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
class Stack { | |
constructor() { | |
this.stack = []; | |
} | |
get length() { | |
return this.stack.length; | |
} | |
push(el) { | |
this.stack.push(el); | |
} | |
pop() { | |
return this.stack.pop() | |
} | |
peek() { | |
if(this.isEmpty()) { | |
return undefined | |
} | |
return this.stack[this.length - 1] | |
} | |
isEmpty() { | |
return this.length === 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment