package com.chinta.datastructure;
import java.util.EmptyStackException;
import java.util.Stack;
public class StackOperation {
public static void showpush(Stack st,int a){
st.push(new Integer(a));
System.out.println("push :"+a);
System.out.println("stack "+st);
}
public static void showpop(Stack st){
System.out.println("pop->");
Integer a=(Integer) st.pop();
System.out.println(a);
System.out.println(st);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack st=new Stack();
showpush(st, 23);
showpush(st, 24);
showpush(st, 25);
showpush(st, 26);
showpop(st);
showpop(st);
showpop(st);
System.out.println("top is"+st.peek());
// showpop(st);
try{
showpop(st);
}
catch(EmptyStackException ex){
ex.printStackTrace();
}
}
}
import java.util.EmptyStackException;
import java.util.Stack;
public class StackOperation {
public static void showpush(Stack st,int a){
st.push(new Integer(a));
System.out.println("push :"+a);
System.out.println("stack "+st);
}
public static void showpop(Stack st){
System.out.println("pop->");
Integer a=(Integer) st.pop();
System.out.println(a);
System.out.println(st);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack st=new Stack();
showpush(st, 23);
showpush(st, 24);
showpush(st, 25);
showpush(st, 26);
showpop(st);
showpop(st);
showpop(st);
System.out.println("top is"+st.peek());
// showpop(st);
try{
showpop(st);
}
catch(EmptyStackException ex){
ex.printStackTrace();
}
}
}
Comments