Skip to content

Instantly share code, notes, and snippets.

@mcardacci
Created April 12, 2015 23:46
Show Gist options
  • Save mcardacci/7c35a5b32f6f9708be93 to your computer and use it in GitHub Desktop.
Save mcardacci/7c35a5b32f6f9708be93 to your computer and use it in GitHub Desktop.
A Queue-like data structure built in ruby
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