# FIFO Queue
#
class Queue

  # Exception class for attempts to draw values from
  # an empty queue.
  #
  class Empty < StandardError
    def initialize
      super("Empty queue")
    end
  end

  # Initialization
  #
  def initialize
    @contents = Array.new
  end

  # Queue is empty if its size is zero
  #
  def empty?
    size = 0
  end

  # Queue size - number of elements
  #
  def size
    @contents.size
  end

  # Add a value to the tail of the queue
  #
  def tail= value
    @contents[@contents.size] =  value
    nil
  end

  # Return the first element in the queue
  # without removing it
  #
  def peek
    raise Empty if empty?
    @contents[0]
  end

  # Return and remove the first queue element
  #
  def head
    value = peek
    @contents.delete_at(0)
    value
  end
end
