Download presentation
Presentation is loading. Please wait.
Published byLewis Joseph Modified over 9 years ago
1
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 “.
2
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.
3
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.
4
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 “-”
5
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 “-”
6
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.
7
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. +
8
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. +
9
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 “*”
10
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.
11
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. +
12
Evaluation of Expressions Infix to Posfix Use posfix to calculate value ab/-cd**-aec+
13
Evaluation of Expressions Infix to Posfix Use posfix to calculate value 510/-72**-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.
14
Evaluation of Expressions Infix to Posfix Use posfix to calculate value 5 10 /- 7 2**-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. = 3
15
Evaluation of Expressions Infix to Posfix Use posfix to calculate value 5 /2**-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. 3 = 5
16
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
17
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
18
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. 1 10 =
19
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.