Docstoc

postfix Postfix Demo The Equation Infix

Document Sample
postfix Postfix Demo The Equation Infix Powered By Docstoc
					                        Postfix Demo: The Equation

        Infix: (1 + (2 * ((3 + (4 * 5)) * 6))) = 277
        Postfix: 1 2 3 4 5 * + 6 * * +                                           = 277

(   1   +   (       2    *   (   (       3   +   (   4       *       5   )   )       *       6   )   )   )




(   1   (   2       (    (   3   (       4   5   )   *       )   +       6   )       *       )   *   )   +

                                                     23 531 138
                                                     20 * + = ==23
                                                     4 * +*62 20276
                                                     138
                                                     276         277

                1        2   3       4       5   *       +       6       *       *       +




                                                                                                             1
                 Postfix Demo: The Stack

What is a ‘STACK’?
At the grocery store, on the canned goods aisle, the cans
are STACKED on top of each other.
      Which one do we take to make sure the stack doesn’t
      fall over?
      How did the store worker put the cans into the
      stack? Where did he or she place the new can?
We take the top item and we place new items on the top.
So does the computer.
To evaluate the problem (1 + (2 * ((3 + (4 * 5)) * 6))), the
computer uses a stack and postfix notation.
             1   2   3   4   5   *   +   6   *   *   +

                                                               2
    Postfix Demo: The Evaluation
    1   2     3    4     5       *    +    6   *     *   +




The Stack

   5
                  4          *        5    =       20
    4
    6
   20
                  3          +       20    =       23
    3
  138
   23

   2
  276             23         *        6    =       138

   1
  277       The Answer
                  2          *       138   =       276

                  1          +       276   =       277

                                                             3

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:32
posted:11/12/2011
language:English
pages:3