diff --git a/stack_basic.java b/stack_basic.java new file mode 100644 index 0000000..c919045 --- /dev/null +++ b/stack_basic.java @@ -0,0 +1,34 @@ +import java.util.*; +public class Program +{ + public static void main(String[] args) + { + Stack st=new Stack<>(); + st.push(10); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.push(20); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.push(30); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.push(40); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.push(50); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + System.out.println(st+" "+st.peek()+" "+st.size()); + st.pop(); + //till here all elements are gone + //so when we again print st.peek it will not print it will give run time error + //so we do not write st.peek function + System.out.println(st+" "+st.size()); + //size comes as zero + } +}