Last active
August 29, 2015 14:04
-
-
Save jayrobin/fa043722cfd0d2ab4697 to your computer and use it in GitHub Desktop.
Ruby implementation of queue
This file contains 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 | |
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