Skip to content

Instantly share code, notes, and snippets.

@libbyschuknight
Created May 5, 2015 23:40
Show Gist options
  • Save libbyschuknight/3bf5f2f2f6a924a1a9a0 to your computer and use it in GitHub Desktop.
Save libbyschuknight/3bf5f2f2f6a924a1a9a0 to your computer and use it in GitHub Desktop.
Liz and Libby's Queue
class Queue
def initialize
@store = []
end
def push(x)
@store.unshift(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
def queue_print
p @store
end
end
our_queue = Queue.new
our_queue.push("Apple")
our_queue.push("Pear")
our_queue.push("Banana")
our_queue.push("Passion Fruit")
our_queue.queue_print
puts "First Element Off: #{our_queue.pop}"
puts "Second Element Off: #{our_queue.pop}"
puts "Third Element Off: #{our_queue.pop}"
our_queue.queue_print
our_queue.pop
puts "Is this empty #{our_queue.empty?}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment