Skip to content

Instantly share code, notes, and snippets.

@jayrobin
Last active August 29, 2015 14:04
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 jayrobin/fa043722cfd0d2ab4697 to your computer and use it in GitHub Desktop.
Save jayrobin/fa043722cfd0d2ab4697 to your computer and use it in GitHub Desktop.
Ruby implementation of queue
class Queue
def initialize(max_size=nil)
@max_size ||= Float::INFINITY
@store = []
end
def enqueue(item)
raise "The queue is full" if self.full?
@store << item
end
def dequeue
raise "The queue is empty" if self.empty?
@store.shift
end
def empty?
@store.empty?
end
def full?
@store.size == @max_size
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment