NOT : Complementation (Unary Operator) (HIGHEST PRIORITY)
Result is TRUE if operand is FALSE and vice versa.
AND : Logical multiplication (PRIORITY LESS THAN NOT
Result is TRUE if both operands are TRUE otherwise FALSE hi
OR : Logical Addition (LOWEST PRIORITY)
Result is FALSE if both operands are FALSE otherwise TRUE
LOGICAL CONSTANTS
YES / TRUE
NO / FALSE
Just For Reference
Q= A*(B+(C+D)*(E+F)/G)*H Convert INFIX Expression into POSTFIX Expression Following the algorithm showing stack status at each step ) Extra Bracket added 22 H 21 * 20 ) 19 G 18 / 17 ) 16 F 15 + 14 E 13 ( 12 * 11 ) 10 D 9 + 8 C 7 ( 6 + 5 B 4 ( 3 * 2 A 1 ( P (Postfix Expression) Description Stack Status Input Element STEP
Evaluation of POSTFIX Expression
Postfix Expression is without parenthesis.
Postfix Expression has only Operands and Operators
Stack is used to hold operand/intermediate results (STACK APPLICATION)
Expression Evaluated from left to right
Some points to remember regarding POSTFIX expressions:
Evaluation of POSTFIX Expression (Algorithm)
Let P be the expression in POSTFIX notation
Expression is Evaluated from left to right
Add ; at the end to mark end of expression P
Scan the postfix expression from left to right taking one element at a time
While (element !=‘;’) repeat the steps 2.1 and 2.2
2.1 if (element = Operand ) it is PUSHed in STACK
2.2 If (element == Operator )
{
POP first element from TOP call it A
POP second element from TOP call it B
Perform OPERATION B operator A
PUSH Result in STACK
}
Pop the value from stack TOP which is result of the expression
{ {
Assignment Stack Applications
post fix , infix notation (2 marks)
Give postfix form of the following expression:
(i) A*(B+(C+D)*(E+F)/G)*H
(ii) A+[(B+C)*(D+E)*F]/G
(iii) A*(B+D)/E-F-(G+H/K)
(iv) ((A-B)*(D/E))/(F*G*H)
(v) (True && false) || !(false||true)
post fix , infix notation (2 marks)
Evaluate the following postfix expression using a stack and show the Contents of stack after each step:
0 comments
Post a comment