Question: Problem 2 : Infix to Prefix Conversion Infix : An expression is called the Infix expression if the operator appears in between the operands in

Problem 2: Infix to Prefix Conversion
Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression. Simply of the form (operand1 operator operand2).
Example : (A+B)**(C-D)
Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).
Example : *+AB-CD (Infix : (A+B)**(C-D))
Write a program that converts an infix (fully parenthesized) expression to a prefix expression. The program will have to handle only the binary operators +,-,?**,,??. parenthesis, letters and numbers.
An example would be an expression like: ((A**(B))+(2**(C3))2**(A)).
The program must convert this expression (infix) to the prefix expression: ??+?**AB**2???2A All expressions of the test cases are expressions with valid syntax.
You are given a InfixtoPrefix.java file fill in your code in that file.
Hint: Use two stacks, one for operators and another for operands (you can use the Java built-in stack).
Input
Read input from a file "in1.txt". Each input is a valid fully parenthesized expression in the infix notation.
Output
For each test case, print the expression converted to prefix expression.
\table[[Input Sample,Output Sample],[(A**2),*A2],[(:((A**2)+c)-d2},??-+?**A2cd2
Problem 2 : Infix to Prefix Conversion Infix : An

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!