Page 507 - Computer science 868 Class 12
P. 507

Operator / has a higher  /                                                A B C * + D

                       precedence than          -
                       operator - currently at  (
                       top. So / pushed to
                       stack

                       Operand E sent to        /                                                A B C * + D E
                       output                   -

                                                (

                       Left parenthesis         )    Closing bracket encountered.                A B C * + D E / -

                       pushed to stack          /    All the operators till opening
                                                -    parenthesis popped and
                                                (    appended to the postfix
                                                     expression


                   b.  Bracket method

                  Ans.  (A + B * C - D / E)
                      = ( ( A + (B * C) ) - ( D / E ) )
                      = ( (A B C * + ) - (D E/) )
                      = A B C * + D E/-
                   3.  Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:

                      False, True, NOT, AND, False, OR, True, AND                                         [CBSE Delhi 2014]

                          Symbol scanned                   Operation                        Stack
                       False                Push                                    False



                       True                 Push                                    True
                                                                                    False

                       NOT                  Pop top operand
                                            NOT True = False                        False

                                            Push False                              False


                       AND                  Pop top two operands
                                            False AND False = False                 False
                                            Push False

                       False                Push                                    False
                                                                                    False








                                                                                                                       505
                                                                                                       Data Structures  505
   502   503   504   505   506   507   508   509   510   511   512