object Main extends App {
case class NodeMut(var item: String, var next: NodeMut)
class QueueOfString {
var first, last: NodeMut = null
def isEmpty: Boolean = first == null
def enqueue(item: String): Unit = {
var oldLast = last
last = NodeMut(item, null)
if (isEmpty) first = last
else oldLast.next = last
}
def dequeue(): String = {
val res = first.item
first = first.next
if (isEmpty) last = null
res
}
}
val l = new QueueOfString
for (n <- 0 until 100) {
l.enqueue(n.toString)
}
for (n <- 0 until 100) {
println(l.dequeue())
}
}