Skip to content

Instantly share code, notes, and snippets.

@oafridi
Last active August 29, 2015 14:07
Show Gist options
  • Save oafridi/9f913078863ede13b34f to your computer and use it in GitHub Desktop.
Save oafridi/9f913078863ede13b34f to your computer and use it in GitHub Desktop.
Queue implementation in Ruby
class Queue
def initialize
@store = []
@max_size = 5
end
def enqueue(x)
raise "Stack is full!" if full?
@store.push x
end
def full?
return true if @store.length == @max_size
false
end
def dequeue
raise "Stack Underflow - The stack is empty" if self.empty?
@store.shift
end
def peek
@store.first
end
def empty?
@store.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment