You are on page 1of 3

Data Structures and Algorithm

Russel Chu & Deuxus Catacutan


Search Method Program
// Java code to demonstrate search() method
import java.util.*;

public class Stack_Demo {


public static void main(String[] args)
{

// Creating an empty Stack


Stack<Integer> STACK = new Stack<Integer>();

// Stacking int values


STACK.push(8);
STACK.push(5);
STACK.push(9);
STACK.push(2);
STACK.push(4);

// Displaying the Stack


System.out.println("The stack is: " + STACK);

// Checking for the element 9


System.out.println("Does the stack contains '9'? "
+ STACK.search(9));
// Checking for the element 10
System.out.println("Does the stack contains '10'? "
+ STACK.search(10));

// Checking for the element 11


System.out.println("Does the stack contains '11'? "
+ STACK.search(11));
}
}

You might also like