Last active
August 29, 2015 14:07
-
-
Save oafridi/9f913078863ede13b34f to your computer and use it in GitHub Desktop.
Queue implementation in Ruby
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 | |
@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