) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression.

Slides:



Advertisements
Similar presentations
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Advertisements

Prefix, Postfix, Infix Notation
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
Evaluate expressions with grouping symbols
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
Arithmetic Expressions
Stacks & Queues Infix Calculator CSC 172 SPRING 2002 LECTURE 5.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
Preorder Traversal with a Stack Push the root onto the stack. While the stack is not empty n pop the stack and visit it.
EXAMPLE 3 Using the Associative Property = = Associative property of addition Add fractions. Write as one. 5 5 Add. 4=
Call Stacks John Keyser. Stacks A very basic data structure. – Data structure: a container for holding data in a program. – Classes, structs can be thought.
EXAMPLE 2 Evaluate exponential expressions a. 6 – Product of a power property = 6 0 Add exponents. = 1 Definition of zero exponent = 6 –
Stack Applications.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Do Now: Evaluate Multiplying Monomials Objectives SWBAT: 1) multiply monomials 2) Simplify expressions involving powers of monomials.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
EXAMPLE 1 Following Order of Operations Music You buy a used guitar for $50. You then pay $10 for each of five guitar lessons. The total cost can be found.
Evaluating a Variable Expression To evaluate a variable expression:
Divide. Evaluate power – 3 = – 3 EXAMPLE – 3 = 3 2 – – 3 = 6 – 3 Multiply. Evaluate expressions Multiply and divide from.

1-2 Order of Operations and Evaluating Expressions.
Basic Data Structures Stacks. A collection of objects Objects can be inserted into or removed from the collection at one end (top) First-in-last-out.
Notes Over 2.8 Rules for Dividing Negative Numbers. ( Same as Multiplying ) If there is an even number of negative numbers, then the answer is Positive.
2.3 – Factoring Polynomials Simple Trinomials. A simple trinomial is a quadratic expression where the leading coefficient is a 1. To factor a simple trinomial.
Reverse Polish Notation Written by J.J. Shepherd.
Operand Addressing And Instruction Representation Tutorial 3.
Prefix, Postfix, Infix Notation. Infix Notation  To add A, B, we write A+B  To multiply A, B, we write A*B  The operators ('+' and '*') go in between.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
Order of Operations and the Distributive Property COURSE 2 LESSON 1-9 Use the Distributive Property to find 7(52). What you think 52 is Finding.
Atholton High School Columbia, Maryland Nifty Assignments: Mighty Cabbage Patch Micro.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
ORDER OF OPERATIONS LESSON 2.
Notes 2.1 Order of Operations PEMDAS If an expression has only numbers and symbols, it is a numerical expression. If it has a variable it is a variable.
LESSON 4-7 EXPONENTS & MULTIPLYING. When we multiply terms with exponents  ADD exponents of like variables.
1-2 Order of Operations Objective: Use the order of operations to evaluate expressions.
ORDER OF OPERATIONS. 1.Perform any operations with grouping symbols. 2.Simplify powers. 3.Multiply and divide in order from left to right. 4.Add and subtract.
Prefix notation in action
Algebraic Expressions
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
MEMORY REPRESENTATION OF STACKS
Adding and Subtracting Linear Expressions
Stack application: postponing data usage
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Stacks – Calculator Application
Visit for more Learning Resources
PART II STACK APPLICATIONS
Overview Introduction General Register Organization Stack Organization
Computer Architecture
Stacks, Queues, and Deques
More About Stacks: Stack Applications
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Sequences COURSE 3 LESSON 12-1
CSE 214 – Computer Science II Stack Applications
3 WARM UP EVALUATING NUMERICAL EXPRESSIONS –
Objective - To multiply integers.
Objective Use multiplication properties of exponents to evaluate and simplify expressions.
Stack Applications Lecture 29 Thu, Apr 5, /23/2019
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
CO4301 – Advanced Games Development Week 3 Parsing Continued
Adding and Subtracting Rational Expressions
More About Stacks: Stack Applications
Evaluating Expressions
Stacks.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r + 0 Init: Push + and 0 onto the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Lparen: Push + and 0 onto the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop + and 0 from the stacks,

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop + and 0 from the stacks, add the 7 7

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop + and 0 from the stacks, add the 7 and stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Operator: Push the + onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r LParen: Push a + and 0 onto the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop a + and 0 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop a + and 0 from the stacks add the 3 3

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop a + and 0 from the stacks add the 3, stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Operator: Push a * onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* LParen: Push a + and 0 onto the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 0 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 0 from the stacks add the 4 4

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the + and 0 from the stacks add the 4, stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Operator: Push the + onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 4 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 4 from the stacks, add the read 4 4

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the + and 4 from the stacks, add the read 4, stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* RParen: Pop the * and 8 and 3 from the stacks, 3

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the * and 8 and 3 from the stacks, multiply the two 24

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the * and 8 and 3 from the stacks, multiply the two, push the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Operator: Push the * onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the * and 24 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the * and 24 from the stacks, multiply by the read 2 2

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop the * and 24 from the stacks, multiply by the read 2, stack the 48

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Operator: Push the * onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the * and 48 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the * and 48 from the stacks, multiply the 2 and 48 2

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop the * and 48 from the stacks, multiply the 2 and 48, stack the 96

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Operator: Push the * onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* LParen: Push a + and 0 onto the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 0 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 0 from the stacks, add the 1 1

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the + and 0 from the stacks, add the 1, stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Operator: Push the + onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 1from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r +*+++* Number: Pop the + and 1from the stacks, add the 2 and 1 2

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* Number: Pop the + and 1from the stacks, add the 2 and 1, stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *++* RParen: Pop the * and 3 and 96 from stacks, 96

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the * and 3 and 96 from stacks, multiply 96 and 3 and stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the + and 7 and 288 from stacks, 7

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the + and 7 and 288 from stacks, add 7 and 288 and stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *+* Operator: Push the * onto the stack

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *+* Number: Pop the * and 295 from the stacks

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r *+* Number: Pop the * and 295 from the stacks, multiply the read 3 and 295 3

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r Number: Pop the * and 295 from the stacks, multiply the read 3 and 295, stack it

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r RParen: Pop the + and 0 and 885 from stacks 0

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r 885 RParen: Pop the + and 0 and 885 from stacks, add the 0 and 885 and stack the result

) Number ) Operator ) Number (7 + (3 * (4 + 4) * 2 * 2 * (1 + 2) ) * 3) OperatorOperands Stacks Using Two Stacks to Evaluate a Simple Arithmetic Expression ( Start Operato r 885 Done: Result is in Operands stack: 885