-
-
Save mario4000/d7814bef593494d025a734e6099be861 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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