在 Scala Stack class
,则使用pop()方法删除并返回堆栈顶部的元素。
函数定义: def pop(): A
返回类型: It removes and returns the element at the top of the stack.
范例1:
// Scala program of pop()
// method
import scala.collection.mutable.Stack
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a stack
var s = Stack("C++", "Java", "Python", "Scala")
// Print the stack
println(s)
// Print the top of the stack
println("Top of the stack: " + s.top)
// Applying pop method
val result = s.pop
// Print the popped element
println("Popped element: " + result)
}
}
输出:
Stack(C++, Java, Python, Scala) Top of the stack: C++ Popped element: C++
范例2:
// Scala program of pop()
// method
import scala.collection.mutable.Stack
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a stack
var s = Stack(1, 2, 3, 4)
// Print the stack
println(s)
// Print the top of the stack
println("Top of the stack: " + s.top)
// Applying pop method
val result = s.pop
// Print the popped element
println("Popped element: " + result)
}
}
输出:
Stack(1, 2, 3, 4) Top of the stack: 1 Popped element: 1
相关用法
- Scala Stack :+()用法及代码示例
- Scala Stack ++:()用法及代码示例
- Scala Stack map()用法及代码示例
- Scala Stack :()用法及代码示例
- Scala Stack last()用法及代码示例
- Scala Stack contains()用法及代码示例
- Scala Stack sum()用法及代码示例
- Scala Stack last()用法及代码示例
- Scala Stack take()用法及代码示例
- Scala Stack max()用法及代码示例
- Scala Stack +:()用法及代码示例
- Scala Stack top()用法及代码示例
- Scala Stack min()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 Scala Stack pop() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。