Iterating circular way
问题 I need iterate through a List but circular way. I need too add new elements to the list and iterate over all elements (olds and news elements), How I do it? Is there any data structure for them? 回答1: I think maybe this is what you want; the ability to add new elements to your list even as you are iterating it. The code is ugly but it seems to work. import scala.collection.mutable.Queue class Circular[A](list: Seq[A]) extends Iterator[A]{ val elements = new Queue[A] ++= list var pos = 0 def