# Postfix to Infix

I am able to understand the infix to postfix, however I am having trouble with putting the parentheses back into the infix if I start with postfix.

Have looked at possibility of using 2 stacks, however I would like to
use only one.

I may not have made it clear.

What I need is to convert it to a fully parenthesized infix expression.

I don't understand how I get the parentheses in right spot

slammer 14

Please help!!

slammer14
Asked:
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
put some code here what U have tried so that we can help U
0
Commented:
What are the elements on your stack?  infix strings?
0
Commented:
You do not need to store the brackets in either the postfix or the prefix notation. The order in which you form the postfix/prefix notation will be different depending on the brackets, thus each time you have such a notation, you know exactly what is the order of execution. Hence, IMO you can restore, rather, reintroduce the brackets when you parse the tree formed by the postfix notation.

for eg. consider the following infix forms:-
(A+B)*C
A+(B*C)

now for the first one the postfix notation will be
AB+C*
and for the second one the notation will be
ABC*+

When you are parsing the tree formed by the above notations, you can remember what was the previous root, and whether its precedence is higher or not. If its precedence is higher, then introduce the brackets.
A+(B*C) gets converted to ABC*+ in the postfix notation, and when converting it back to infix, it gets converted to A+B*C, no brackets assuming * has higher precedence over +.
Similarly, AB+C* gets converted to (A+B)*C.

I hope I am clear.
Regards,
- Amit.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Hi,
Here I am giving how we can evaluate postfix expression

Suppose the postfix expression is
ab+c*
The corressponding infix expression is
(a+b)*c

element   stack

a         a       <-  Top
b         a,b     <-  Top
+         perform b+a & result is
put onto top of the stack(a)
c         a,c     <-  Top
*         a*c

I think this will help U.

Sisu
0
Author Commented:
Edited text of question.
0
Author Commented:
Sisu thanks it helps a little, however I don't need to calculate answer I just have to give the expression.

My email is slammer14@hotmail.com

Thanks
slammer
0
Author Commented:
Adjusted points to 50
0
Commented:
While evaluation is easy from postfix, you may find infix conversion more convenient from prefix.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.