Skip to content

Instantly share code, notes, and snippets.

@tal
Created December 13, 2010 19:06
Show Gist options
  • Select an option

  • Save tal/739427 to your computer and use it in GitHub Desktop.

Select an option

Save tal/739427 to your computer and use it in GitHub Desktop.
Stack class with built in min value
class Stack
def initialize
@main = []
@min = []
end
def push val
@main << val
@min << val if val <= min
val
end
def pop
val = @main.pop
@min.pop if min == val
val
end
def min
@min.last
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment