Created
April 12, 2015 23:46
-
-
Save mcardacci/7c35a5b32f6f9708be93 to your computer and use it in GitHub Desktop.
A Queue-like data structure built in ruby
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 Queue | |
attr_reader :store | |
def initialize | |
@store = [] | |
end | |
def enqueue(x) | |
store.push(x) | |
end | |
def dequeue | |
store.shift | |
end | |
def peek | |
store.first | |
end | |
end | |
queue = Queue.new | |
p queue.enqueue("this") == ["this"] | |
p queue.enqueue("that") == ["this","that"] | |
p queue.peek == "this" | |
p queue.dequeue == "this" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment