SizedQueue
class SizedQueue < Array def initialize(n) @N = n @i = 0 end def push(x) ret = self[@i] self[@i] = x @i = (@i+1) % @N return ret end def pop() old_i = @i @i = (@i+@N-1) % N return self[old_i] end end
class SizedQueue < Array def initialize(n) @N = n @i = 0 end def push(x) ret = self[@i] self[@i] = x @i = (@i+1) % @N return ret end def pop() old_i = @i @i = (@i+@N-1) % N return self[old_i] end end