Created
March 31, 2012 16:49
-
-
Save cristianrasch/2266674 to your computer and use it in GitHub Desktop.
Ruby queue implementation
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
#!/usr/bin/env ruby | |
class Queue | |
def initialize | |
@arr = [] | |
end | |
def enqueue(val) | |
@arr << val | |
end | |
def dequeue | |
@arr.shift | |
end | |
def each | |
@arr.each { |e| yield e } | |
# while e = dequeue | |
# yield e | |
# end | |
end | |
end | |
if __FILE__ == $0 | |
q = Queue.new | |
(1..10).each { |i| q.enqueue i } | |
q.each { |e| p "Element is: #{e}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment