Convert the given infix expression A+B^C+(D*E/F) *G into its postfix
expression, and evaluate the same using stack. Here A=3, B=5, C=2, D=7, E=4,
F=1, G=8.
Answers
Answered by
0
a=3,b=5,c=2,d=7,e=4,f=1,g=8
Answered by
0
The postfix expression for the given infix expression A+B^C+(D*E/F) *G is ABC^+DE*F/ G*+.
- An infix expression is a typical expression made up of operators and operands. Operands come first in a postfix expression, then operators.
- In this instance, we convert infix to postfix using stacks. We have a single input string, an operator stack, and an output stack. The operator's stack functions as FILO (First In Last Out). The output stack operates using FIFO (First In First Out).
The algorithm that follows transforms infix into postfix.
- From left to right, read the input string character by character.
- Put the character in the output stack if it is an operand.
- Push the character into the operators' stack if it is an operator and the operators' stack is empty.
- If the operator's stack is not empty, the following scenarios may occur.
- Push the scanned operator into the operand's stack if its precedence is higher than that of the operator at the top of the stack.
- Pop the operators from the operand's stack until we find one with a lower precedence than the scanned character if the precedence of the scanned operator is less than or equal to the top operator of the operator's stack. No matter what the precedence level of a scanned character is, never pop out ('(') or (')').
- Push the character into the operator's stack if it is an opening round bracket ( '(' ).
- Open operators from the operator stack until we find an opening bracket ('(') if the character is a closing round bracket (')').
- Pull all of the remaining operators out of the operator's stack and push them into the output stack at this point.
- For A=3, B=5, C=2, D=7, E=4, F=1, G=8, the postfix expression would be 352^+74*1/ 8*+ and the result of the expression will be 231.
To learn more:
https://brainly.in/textbook-solutions/q-convert-following-infix-notation-expression-equivalent-postfix
https://brainly.in/textbook-solutions/q-converting-following-infix-expression-postfix-notation-b-1
#SPJ2
Similar questions