Evaluation of Expressions Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data.

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

Inverting a Singly Linked List Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.
Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.
Stack & Queues COP 3502.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
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)
Shunting-yard algorithm Infix to postfix conversion Based on
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Arithmetic Expressions
Topic 15 Implementing and Using Stacks
Introduction to Stacks What is a Stack Stack implementation using arrays. Application of Stack.
1 Postfix Demo: The Equation Infix: (1 + (2 * ((3 + (4 * 5)) * 6))) Postfix: * + 6 * * + 3+1(2(*((+45*)*)6))()(45*)3(+)(*6)(2*)+1() 3+12*+45**6.
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 Notation (RPN) & Stacks CSC 1401: Introduction to Programming with Java Week 14 – Lecture 2 Wanda M. Kunkle.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
CST Razdan et al Razdan with contribution from others 1 Chapter 6 Stacks Anshuman Razdan Div of Computing.
1 CSCD 326 Data Structures I Infix Expressions. 2 Infix Expressions Binary operators appear between operands: W - X / Y - Z Order of evaluation is determined.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
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.
Topic 15 Implementing and Using Stacks
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
More About Stacks: Stack Applications Dan Nguyen CS 146, Spring 2004 Professor Sin-Min Lee.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Stack Applications.
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Stacks and Queues Introduction to Computing Science and Programming I.
Quick Sort Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures.
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.
Left Child-Right Sibling Representation Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.
Reverse Polish Notation Written by J.J. Shepherd.
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.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
Stack ADT Operations Push, Pop, Top, isEmpty Application: Expression Evaluation Arithmetic Expression Infix-to-Postfix Postfix to Quadruples Boolean Expressions.
Level Order Traversal of a Binary Tree Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
Stacks. Stack ADT where we can only work with "top" – Top() : get value on top – Pop() : remove value on top – Push(value) : put new value on top.
Review Use of Stack Introduction Stack in our life Stack Operations
Stacks Access is allowed only at one point of the structure, normally termed the top of the stack access to the most recently added item only Operations.
Revised based on textbook author’s notes.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
Stack application: postponing data usage
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Stacks – Calculator Application
Visit for more Learning Resources
Stacks – Calculator Application
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks, Queues, and Deques
Stack ADT Operations Application: Expression Evaluation
Lecture No.07 Data Structures Dr. Sohail Aslam
Infix to Postfix Conversion
COMPUTER 2430 Object Oriented Programming and Data Structures I
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Infix to Postfix Conversion
Topic 15 Implementing and Using Stacks
Queue Applications Lecture 31 Tue, Apr 11, 2006.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Stacks.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
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:

Evaluation of Expressions Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “.

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. (ab/(-c+d))**()-aec\0 Put operators to stack and numbers to array.

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. ( a b/(-c+d))**()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack.

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. ( a b / ( -c+d))**()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, “(“ push on any operators and pop when “)” push to stack. Not high order than “-”

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. ( a b / ( - c +d))**()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. Not high order than “-”

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. ( a b / ( - c + d ) )**()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored.

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. ( a b / - c d )**()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored. +

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. a b / - c d **()-aec\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored. +

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. a b / - c d * * ( ) - a e c\0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored. + Not high order than “*”

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. a b / - c d * * - a e c \0 Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored. + “\0” is lowest order operator, so pop all the operators in stack.

Evaluation of Expressions Infix to Posfix Use stack to change infix into posfix First, we prepare a stack and an array. a b / - c d * * - a e c Put operators to stack and numbers to array. If the operator is high order than the top term of stack, push it to stack, otherwise pop the top term to array. However, the ( ) operators without following the rules, push “(“ on any operators and pop when push “)” to stack. If push “)” to the stack, pop the operators between ( ) to array and pop the ( ) without being stored. +

Evaluation of Expressions Infix to Posfix Use posfix to calculate value ab/-cd**-aec+

Evaluation of Expressions Infix to Posfix Use posfix to calculate value 510/-72** Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack.

Evaluation of Expressions Infix to Posfix Use posfix to calculate value 5 10 /- 7 2** Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack. = 3

Evaluation of Expressions Infix to Posfix Use posfix to calculate value 5 /2** Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack. 3 = 5

Evaluation of Expressions Infix to Posfix Use posfix to calculate value 5 /**-5157 Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack. 5 =1

Evaluation of Expressions Infix to Posfix Use posfix to calculate value **-5157 Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack. 1 =10

Evaluation of Expressions Infix to Posfix Use posfix to calculate value **7 Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack =

Evaluation of Expressions Infix to Posfix Use posfix to calculate value * 7 Push the item of array to stack If the item is operator, operating the two top of stack with this token and push to stack. 10 = 70 answer of the expressions