stack

import java.util.*;
class stack
{
public static void main(String args[])
{
Stack stack1 = new Stack();
try
{
if(stack1.empty())
System.out.println("Stack is Empty");
else
System.out.println("Stack is not Empty");
stack1.push(new Integer(0));
stack1.push(new Integer(1));
stack1.push(new Integer(2));
stack1.push(new Integer(3));
stack1.push(new Integer(4));
stack1.push(new Integer(5));
stack1.push(new Integer(6));

if(stack1.empty())
System.out.println("Stack is Empty");
else
System.out.println("Stack is not Empty");

System.out.println("Hello Got at:"+stack1.search(new Integer(50)));

System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());
System.out.println((Integer) stack1.pop());

System.out.println((Integer) stack1.pop());
}
catch (EmptyStackException e)
{
System.out.println(e);
}
if(stack1.empty())
System.out.println("Stack is Empty");
else
System.out.println("Stack is not Empty");
}
}

Comments

Popular Posts