Question: I need a java code, that will be implemented by stack and queue interfaces Postfix expression to infix expression : Read the postfix expression from
I need a java code, that will be implemented by stack and queue interfaces
Postfix expression to infix expression:
Read the postfix expression from left to right and to the following:
If the current character in the postfix is a space, ignore it.
If the current character is an operand, push it on the stack
If the current character is an operator,
Pop the top 2 values from the stack. If there are fewer then 2 values throw an error
Create a string with 2nd value and then the operator and then the 1st value popped from the stack.
Encapsulate the resulting string within parenthesis
Push the resulting string back to the stack
When the postfix expression has been read:
If there is only one value in the stack it is the infix string, if more than one
value, throw an error
Evaluating a postfix expression
Read the postfix expression from left to right and to the following:
If the current character in the postfix expression is a space, ignore it.
If the current character is an operand or left parenthesis, push on the stack
If the current character is an operator,
Pop the top 2 values from the stack. If there are fewer then 2 values throw an error
Perform the arithmetic calculation of the operator with the first popped value as the right operand and the second popped value as the left operand
Push the resulting value onto the stack
When the postfix expression has been read:
If there is only one value in the stack it is the result of the postfix expression, if
more than one value, throw an error
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
