Last active
December 13, 2015 22:59
-
-
Save dbc-challenges/4988728 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
# A very basic Stack implemented with an array | |
# Makes use of the built in #pop and # push methods that exist for arrays. | |
class Stack | |
def initialize | |
@store = [] | |
end | |
def push(x) | |
@store.push x | |
end | |
def pop | |
raise "Stack Underflow - The stack is empty" if self.empty? | |
@store.pop | |
end | |
def peek | |
@store.last | |
end | |
def empty? | |
@store.empty? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment