Skip to content

Instantly share code, notes, and snippets.

@miwarin
Created April 30, 2014 11:16
Show Gist options
  • Save miwarin/305a24b5791bd29308e2 to your computer and use it in GitHub Desktop.
Save miwarin/305a24b5791bd29308e2 to your computer and use it in GitHub Desktop.
キュー自作しない
#: coding: utf-8
class Queue
def initialize()
@queue ||= []
end
def get()
return nil if @queue.empty?
return @queue.shift()
end
def put(item)
@queue.push(item)
end
end
def main(argv)
max = 5
queue = Queue.new()
0.upto(max - 1) {|n|
queue.put(n)
}
0.upto(max -1) {|n|
puts queue.get()
}
end
main(ARGV)
=begin
>ruby queue1.rb
0
1
2
3
4
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment