Page 500 - Computer science 868 Class 12
P. 500

21             {  System.out.println("Popping "+a[top--]); // decrease top by 1
                22             }

                23          }
                24          void display()  //display
                25          { for(int i=top;i>=0;i--)

                26               System.out.println(a[i]);

                27          }
                28          public static void main(int s)
                29          { Stack ob=new Stack(s);

                30            Scanner sc= new Scanner(System.in);
                31            int ch,n;

                32            do    //menu
                33            { System.out.println("1.Push  / 2.Pop / 3.Display...enter choice");

                34              ch=sc.nextInt();
                35              switch(ch)

                36              {case 1:
                37              System.out.println("Enter number to push");

                38              n=sc.nextInt();
                39              ob.push(n);

                40              break;
                41              case 2:

                42              ob.pop();
                43              break;

                44              case 3:
                45              ob.display();

                46              break;
                47              default: System.out.println("Exit");

                48             }
                49          } while(ch>=1&&ch<=3);
                50         }

                51       }












                498498  Touchpad Computer Science-XII
   495   496   497   498   499   500   501   502   503   504   505