Created
September 21, 2008 04:04
-
-
Save Sixeight/11837 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
class EmptyStackError < StandardError; end | |
class Stack | |
def initialize | |
@stack = [] | |
@size = 0 | |
end | |
def empty? | |
@size == 0 | |
end | |
def push(val) | |
@size += 1 | |
@stack << val | |
end | |
def pop | |
raise EmptyStackError if @stack.empty? | |
@size -= 1 | |
@stack.pop | |
end | |
def size | |
@size | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment