class Hamster::Queue
def clear
def clear EmptyQueue end
def dequeue
def dequeue front = @front rear = @rear if front.empty? return EmptyQueue if rear.empty? front = rear.reverse rear = EmptyList end transform do @front = front.tail @rear = rear end end
def empty?
def empty? @front.empty? && @rear.empty? end
def enqueue(item)
def enqueue(item) transform { @rear = @rear.cons(item) } end
def eql?(other)
def eql?(other) instance_of?(other.class) && to_list.eql?(other.to_list) end
def head
def head return @front.head unless @front.empty? @rear.last end
def initialize
def initialize @front = @rear = EmptyList end
def inspect
def inspect to_list.inspect end
def size
def size @front.size + @rear.size end
def to_a
def to_a to_list.to_a end
def to_ary
def to_ary to_list.to_ary end
def to_list
def to_list @front.append(@rear.reverse) end