Queue Continuum

Difficulty:
Elementary

Tags:
classes, queues

Instructions:
Write a queue class. A queue is a data structure where elements are added at the end and removed from the front.

Code:
class Queue
  ___
end

queue = Queue.new([5, 6, 7, 8])

assert_equal queue.pop, 5
assert_equal queue.pop, 6
assert_equal queue.push([4, 2]), true
assert_equal queue.pop(2), [7, 8]
assert_equal queue.to_a, [4, 2]

Your Solution

Ruby 1.9.3

Back to Problems