Created
May 5, 2015 23:40
-
-
Save libbyschuknight/3bf5f2f2f6a924a1a9a0 to your computer and use it in GitHub Desktop.
Liz and Libby's Queue
This file contains hidden or 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 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