Skip to content

Instantly share code, notes, and snippets.

@mario4000
Forked from kenmazaika/queue.rb
Created October 18, 2017 10:14
Show Gist options
  • Save mario4000/d7814bef593494d025a734e6099be861 to your computer and use it in GitHub Desktop.
Save mario4000/d7814bef593494d025a734e6099be861 to your computer and use it in GitHub Desktop.
a = []
a.push(1) # enqueue the number 1 in the queue
a.push(2) # enqueue the number 2 in the queue
a.push(3) # enqueue the number 3 in the queue
# dequeue the first element, 1 has been in the queue longest
puts a.shift # => displays 1
a.push(4) # enqueue the number 4 in the queue
# dequeue the next element. 1 has been tended to
# already, so tend to the element that has been in
# the queue the longest, in this case 2
puts a.shift # => displays 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment