The stack.pop()
function in Scala returns the element that is available at the top of the stack and removes that element from the stack.
Figure 1 shows the visual representation of the stack.pop()
function.
The following module is required in order to use the function:
scala.collection.mutable.Stack
stack_name.pop();
// where the stack_name is the name of the stack
This function does not require a parameter.
This function returns the element available at the top of the stack and removes that element from the stack.
The following code shows how to use the stack.pop()
function.
import scala.collection.mutable.Stackobject Main extends App {var stack = Stack[Int]()stack.push(0);stack.push(2);stack.push(5);stack.push(3);stack.push(1);//Stack before removingprintln("Following are the elements in Stack before removing: " + stack);//Stack after removingprintln("The element removed from the front of Stack: "+stack.pop());println("Following are the elements in Stack after removing: " + stack);}