• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

having problems with parenthesis in postfix to infix conversion

hi, this is my first time but i really need help.

The program i'm writing is a postfix to infix converter in c++, the conversion part concerning the placement of operators is working fine (i'm using a stack) and didn't take much time but i'm having problems dealing with the parenthesis, in part because i'm trying to avoid useless ones. For example: (a*b)+(c*d)=a*b+c*d. If someone has an idea to solve my problem or who can tell me what propreties have () regarding operators in postfix notation, please let me know.
Thank you.
0
rocketsbay
Asked:
rocketsbay
1 Solution
 
imladrisCommented:
The way the operator stack normally works for that algorithm, is to have weaker bindings flush stronger bindings from the stack, right?
So, for example, if a + is stashed in the stack, and then a * comes along you keep going.
On the other hand, if a * is in the operator stack and then you find a +, the + causes the * to be flushed to the output stream, before the * is put on the stack.

In keeping with that, the left paren should be the weakest "binding" or priority. This means it will stay in the stack when "stronger" operators come along.

Then, when you get the right paren, flush all the operators in the stack, until you hit the left paren, and pop that off as well.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now