How would I go about doing this? Write a program that converts an infix (fully p
ID: 3726691 • Letter: H
Question
How would I go about doing this?
Write a program that converts an infix (fully parenthesized) expression to a prefix expression. Like you know, the terms "in" and "pre" are according with the operator's position. The program will have to handle only the binary operators +,-, *, /, ^. parenthesis, letters and numbers. An example would be an expression like: (((A*B)+(2*(CA3))/(2*A)) The program must convert this expression (infix) to the prefix expression: /+*AB*2AC3*2A All expressions of the test cases are expressions with valid syntax. Input Read input from a file "in1.txt". The first line of input is an integer N (NExplanation / Answer
Infix expression easy for human calculations but it is very tough for computer because in the infix expression contains operator precedence in prefix or postfix expressions doesn't contain any parenthesis.
now we are converting infix expression to prefix expression.
converting of infix expression to prefix expression somewhat complicate compare to converting infix to postfix.
so here i am providing easy logic.
1.scan the infix expression
2. reverse the infix expression
3.convert the reversed infix expression to postfix expression
4.reverse the postfix expression => this is the prefix expression of the given infix expression.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.