Created
April 12, 2015 23:42
-
-
Save mcardacci/3280e2a72005b852811a to your computer and use it in GitHub Desktop.
A Queue-like data structure built in ruby
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 | |
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