Question

In: Computer Science

Convert the expression into postfix notation 19 + 2 ∗ 5  + (1 - 6/(1 ∗ 2))

Convert the expression into postfix notation
19 + 2 ∗ 5  + (1 - 6/(1 ∗ 2))

Solutions

Expert Solution

SOLUTION:

19 2 ∗ 5 + 1 61 ∗ 2/-+

STEP-BY-STEP SOLUTION

Input String                   Output Stack                Operator Stack
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    1       
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19      
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19      
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19                             +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19                             +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2                       +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2                       +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗                     +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗                     +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5                       +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5                       +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5                       +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 +                     +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 +                     +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 +                     +(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1               +(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1               +(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1               +(-
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1               +(-
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 6             +(-
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 6             +(-/
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 6             +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61            +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61            +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗              +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗              +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗ 2            +(-/(
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗ 2            +(-/
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗ 2/-        +
19 + 2 ∗ 5 + (1 - 6/(1 ∗ 2))    19 2 ∗ 5 + 1 61 ∗ 2/-+  

Related Solutions

(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...
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.
The following postfix expression 2 6 + 3 5 - / evaluates to Group of answer...
The following postfix expression 2 6 + 3 5 - / evaluates to Group of answer choices -1 1 -4 4 this is not a postfix expression In an array implementation of the StackInterface where push() and pop() are O(1), the top of the stack is Group of answer choices the first entry in the array the last occupied entry in the array the second entry in the array the entry before the last ocuppied entry in the array the...
Convert an infix expression to its postfix representation in JAVA
Convert an infix expression to its postfix representation in JAVA
Using Java 8. Write a program that reads an expression in postfix notation, builds the expression...
Using Java 8. Write a program that reads an expression in postfix notation, builds the expression tree and prints the expression in prefix and infix notation and evaluates the expression. (Hint use a stack)
the postfix notation for (7-4)+2 is
the postfix notation for (7-4)+2 is
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2...
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2 + 5 * 8 4 / - The program should read a postfix expression consisting of single digits and operators into a StringBuilder, The program should read the expression and evaluate it (assume it's valid). The algorithm to evaluate a postfix expression is shown below. Use +, -, *, /, and ^. ^ is the exponent. Append a right parenthesis ') ' to the...
Your assignment for this program is to evaluate a numeric expression in postfix notation using a...
Your assignment for this program is to evaluate a numeric expression in postfix notation using a dynamic (pointer based) stack. As stated in the handout, in order to evaluate a numeric expression, a compiler converts an infix numeric expression to postfix notation and then it uses an algorithm and a stack to evaluate the expression. Your program should implement the pseudocode algorithm described in the attached handout. Your program will read and evaluate expressions stored in an input file (infile.txt)....
1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b)...
1) Consider the following infix expressions. What is the equivalent postfix (reverse Polish notation) expression? 16/(5+3)b) A*B+C*Dc) X × Y + W × Z + V × U 2) Consider the postfix (reverse Polish notation) 10 5 + 6 3 - /. What is the equivalent infix expression?
Postfix notation is an unambiguous way of writing an arithmetic expression without parentheses. It is defined...
Postfix notation is an unambiguous way of writing an arithmetic expression without parentheses. It is defined so that if “(exp1)op(exp2)” is a normal, fully parenthesized expression whose operation is op, the postfix version of this is “pexp1 pexp2 op”, where pexp1 is the postfix version of exp1 and pexp2 is the postfix version of exp2. The postfix version of a sin- gle number or variable is just that number or variable. For example, the postfix version of "((5+2) * (8-3))/4"...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT