Ah! a good friend just pointed out that step (2) is not quite simple.
A postfix expression bases precedence by the operator position due to
lack of parentheses. I am not sure about the code to convert from
postfix to infix. It *has* to insert parentheses generously to add to
the precedence information lost. So, it will eventually again return
back (A+(B*C)).
So, my approach will not work. Any solutions then?

On Jul 26, 3:26 pm, bharath <bharath.sri...@gmail.com> wrote:
> Given an expression (A+(B*C)), remove redundant parentheses. Output in
> this case should be A+B*C.
> My initial solution:
> (1) Convert expression from infix to postfix (or prefix) [This way,
> all parentheses are removed]
> (2) Now, convert postfix (or prefix) expression back to infix.
>
> Is there a better way of doing this?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to