Skip to content

Instantly share code, notes, and snippets.

@mcardacci
Created April 12, 2015 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcardacci/3280e2a72005b852811a to your computer and use it in GitHub Desktop.
Save mcardacci/3280e2a72005b852811a 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