Page 508 - Computer science 868 Class 12
P. 508

OR                  Pop top two operands

                                         False OR False = False                   False
                                         Push False

                     True                Push                                     True
                                                                                  False

                     AND                 Pop top two operands                     False

                                         False AND True = False
                                         Push False
                                         Pop all

              Ans.  False
                4.  Evaluate  the  following  postfix  expression.  Show  the  status  of  stack  after  execution  of  each  operation:
                    5, 2, *, 50, 5, /, 5, –, +.                                                     [CBSE All India 2013]


                       Symbol scanned        Operation             Stack               Result

                             5          Push                         5

                             2          Push                        5, 2

                             *          Pop                         5, 2

                                        Push                        10          5*2 = 10

                             50         Push                       10, 50

                             5          Push                      10, 50, 5


                             /          Pop                       10, 50, 5     50/5 = 10
                                        Push                       10, 10

                             5          Push                      10, 10, 5

                             -          Pop                       10, 10, 5     10 - 5 = 5

                                        Push                       10, 5

                             +          Pop                        10, 5        10 + 5 = 15
                                        Pop all

              Ans. 15
              The algorithm to convert an Infix expression to its Prefix form is given below.
              Step 1:  Start

              Step 2:  Reverse the infix expression. The left parenthesis changes to right parenthesis and vice versa.

              Step 3:  Repeat Step 4 to step 8 by reading the reversed infix expression from left to right one element at a time.
              Step 4:  If the symbol scanned is an operand, append it to the postfix expression.



                506506  Touchpad Computer Science-XII
   503   504   505   506   507   508   509   510   511   512   513