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!!

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.

put some code here what U have tried so that we can help U
What are the elements on your stack?  infix strings?
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:-

now for the first one the postfix notation will be
and for the second one the notation will be

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.
- Amit.

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.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  Here I am giving how we can evaluate postfix expression

Suppose the postfix expression is
The corressponding infix expression is

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.

slammer14Author Commented:
Edited text of question.
slammer14Author 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

slammer14Author Commented:
Adjusted points to 50
While evaluation is easy from postfix, you may find infix conversion more convenient from prefix.
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

From novice to tech pro — start learning today.