30 likes | 286 Views
(. 1. +. (. 2. *. (. (. 3. +. (. 4. *. 5. ). ). *. 6. ). ). ). (. 1. (. 2. (. (. 3. (. 4. 5. ). *. ). +. 6. ). *. ). *. ). +. 1. 2. 3. 4. 5. *. +. 6. *. *. +. Postfix Demo: The Equation. Infix: (1 + (2 * ((3 + (4 * 5)) * 6))). = 277. = 277.
E N D
( 1 + ( 2 * ( ( 3 + ( 4 * 5 ) ) * 6 ) ) ) ( 1 ( 2 ( ( 3 ( 4 5 ) * ) + 6 ) * ) * ) + 1 2 3 4 5 * + 6 * * + Postfix Demo: The Equation Infix: (1 + (2 * ((3 + (4 * 5)) * 6))) = 277 = 277 Postfix: 1 2 3 4 5 * + 6 * * + 4 * 5 = 20 20 + 3 = 23 23 * 6 = 138 138 * 2 = 276 276 + 1 = 277
1 2 3 4 5 * + 6 * * + 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.
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 23 * 6 = 138 2 276 1 277 2 * 138 = 276 The Answer 1 + 276 = 277