Question

In: Computer Science

2. Convert the following infix form expression into the postfix form expression by using a stack:...

2. Convert the following infix form expression into the postfix form expression by using a stack:

A+(B*(C-D)+E)/F-G*H

Show the stack after each push/pop.

Solutions

Expert Solution

Convert the infix to postfix expression:-

  • Postfix expression is a collection of operators and operands in which the operator is placed after the operands. that means, in a postfix expression the operator follows the operands.
  • Postfix expression has a structure:-
  • operand1 operand2 operator example is ab+
  1. Read all the symbols one by one from left to right
  2. if the reading symbol is an operand, then push to onto the stack
  3. if the reading symbol is operator(+,-,*,/) then perform TWO pop operations and store two popped operand in different variables.
  4. finally perform a pop operation and display the popped value as final result
Symbol Stack Postfix
A ( A
+ (+ A
( (+( A
B (+( AB
* (+(* AB
( (+(*( AB
C (+(*( ABC
- (+(*(- ABC
D (+(*(- ABCD
) (+(* ABCD-
+ (+(+ ABCD-*
E (+(+ ABCD-*E
) (+ ABCD-*E+
/ (+/ ABCD-*E+
F (+/ ABCD-*E+F
- (- ABCD-*E+F/+
G (- ABCD-*E+F/+G
* (-* ABCD-*E+F/+G
H (-* ABCD-*E+F/+GH
) ABCD-*E+F/+GH*-

Here we are Assuming the brackets outside the whole expression by default to convert it into postfix.


Related Solutions

java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expres
java Convert the following Infix expression to a Postfix expression. Show all work                            Infix Expression                                                 Stack                             Postfix Expression ---------------------------------------------------------------------------------------------------------------------------- 8 - 9*(2 + 1/4) + 3*7                                                     (empty)                            (blank) Evaluate the following Postfix expression. Once again, show all work.            Postfix                                               Stack                     Result           ---------------------------------------    --------------------    --------------            2 7 + 12 4 / * 8 5 + -
Using a stack, write a program that turns a simple infix arithmetic expression into a postfix...
Using a stack, write a program that turns a simple infix arithmetic expression into a postfix expression. For example, 1 + 2 * 3 becomes 2 3 * 1 +. Also, evaluate the expression to ensure the expression is correct.
(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses....
(Convert infix to postfix) Note: Postfix notation is a way of writing expression without using parentheses. For example, the expression ( 11 + 12 ) * 13 would be written as 11 12 + 13 * Assume that ALWAYS there is a space between operands and operators in the input expression. Use two stacks, one to store the operands and one to store the operators. Your program only accpets following operators : ( ) + - / * Write a...
Convert an infix expression to its postfix representation in JAVA
Convert an infix expression to its postfix representation in JAVA
Using STL stack class, implement in C++ a function that converts an infix expression to postfix...
Using STL stack class, implement in C++ a function that converts an infix expression to postfix expression,
Write a java class program to convert from INFIX TO POSTFIX Using stack operations
Write a java class program to convert from INFIX TO POSTFIX Using stack operations
Using java.util.Stack and java.util.StringTokenizer to write a program that converts an infix expression to a postfix...
Using java.util.Stack and java.util.StringTokenizer to write a program that converts an infix expression to a postfix expression using data from infix.dat. Make sure your program can handle negative number. If the input expression can’t be converted, display error message.(1.5 points) (Should remove parentheses) infix.dat 5 * 6 + -10 3 - 2 + 4 7 ( 3 * 4 - (2 + 5)) * 4 / 2 10 + 6 * 11 -(3 * 2 + 14) / 2 2...
Introduced to data structure using java 2)One of the applications of stack is to convert infix...
Introduced to data structure using java 2)One of the applications of stack is to convert infix expressions to postfix. Given the following infix expression, use the stack method to convert it to postfix. Show your work. x - y / (a + b) + z 3)write a generic method to find the maximum of three variables of generic type (i.e. type T). Note that you must use the compareTo method to compare the values. Also, the code must return one...
Write a program that takes an infix expression as input and produces a postfix expression. The...
Write a program that takes an infix expression as input and produces a postfix expression. The infix and postfix expressions are in the form of vectors of strings. We will test with a main method that takes a file name as input from the command line. We will test your implementation using printPostFix() method.   There are sample input and output files in this folder. You may edit the header file. Example 1 infix expression = apple + banana * cat...
Implement an infix expression to postfix expression convertor in C++. Note: - Support +, -, *,...
Implement an infix expression to postfix expression convertor in C++. Note: - Support +, -, *, /, ( and ) in infix expressions. - Operands will be nonnegative only. - Assume infix expressions are valid and well formatted (one blank space to separate operand/operator) For example, - 3 * 4 + 5 ➔ 3 4 * 5 + - 3 + 4 * 5 ➔ 3 4 5 * + - (3 + 4) * (5 + 6) ➔ 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT