Stacks follow the
The stack.isEmpty()
function in Scala tests whether the stack is empty by returning true
if the stack is empty. Otherwise, it returns false
.
The image below shows the visual representation of the stack.isEmpty
function.
stack_name.isEmpty();
// where the stack_name is the name of the stack
The following module is required in order to use the function:
scala.collection.mutable.Stack
The stack.isEmpty
function does not require any parameters.
If the stack is empty, the stack.isEmpty
function returns true
. Otherwise, it returns false
.
The following code shows how to use the stack.isEmpty
function.
import scala.collection.mutable.Stackobject Main extends App {//filled stackvar stack_1 = Stack[Int]()stack_1.push(0);stack_1.push(2);stack_1.push(5);stack_1.push(3);stack_1.push(1);println("Stack_1 is empty: " + stack_1.isEmpty);//empty stackvar stack_2 = Stack[Int]()println("Stack_2 is empty: " + stack_2.isEmpty);}