2014年03月06日 星期四 09:53
Stack是一种“后进先出”(LIFO)的容器,主要的API是入栈(push)和出栈(pop)两种操作。
If you need a last-in-first-out sequence, you can use a Stack, which also comes in both mutable and immutable versions in the Scala collections library. You push an element onto a stack with push, pop an element with pop, and peek at the top of the stack without removing it with top.
编程示例如下:
import scala.collection.mutable.Stack
object S016_Stack {
def main(args: Array[String]): Unit = {
val s=Stack[Int]()
for(i <- 0 until 10){
s.push(i)
}
while(s.size > 0){
println(s.pop)
}
}
}
参考资料:
Zeuux © 2025
京ICP备05028076号