Page 502 - Computer science 868 Class 12
P. 502

21              else
                22              { top--;   // decrease top by 1

                23                return stud[top+1];
                24               }
                25           }

                26           void display()

                27           { System.out.println("Current content in stack");
                28              for(int i=top;i>=0;i--)
                29             { System.out.println(stud[i]);}

                30           }
                31           public static void main(int s)

                32           { Register ob=new Register(s);
                33             String r;

                34             int ch;
                35             Scanner sc=new Scanner(System.in);

                36             do
                37             { System.out.println("1. Push   \n  2. Pop   \n 3. Display   \n  4. Exit \n");

                38               ch=sc.nextInt();
                39               switch(ch)

                40               { case 1:
                41                     System.out.println("Enter name to store in stack");

                42                     r=sc.next();
                43                     ob.push(r);

                44                     break;
                45                 case 2:

                46                      r=ob.pop();
                47                      if(r.equals("$$"))

                48                        System.out.println("Underflow... stack empty");
                49                      else
                50                        System.out.println(r+" popped");

                51                      break;

                52                 case 3:
                53                      ob.display();
                54                      break;





                500500  Touchpad Computer Science-XII
   497   498   499   500   501   502   503   504   505   506   507