• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can anyone convert this infix expression to postfix

Originally posted by: AgaBoogaBoo
5(2+)*3(1-)+4(1+)

Thanks but if this is indeed correct, my java program is doing something wrong.
My program spit out:
52+31-41++*.

For an answer of 49.

Am i doing something wrong? If so, can anyone spot the error?

Thanks.
 
If I new the difference I could probably help you with the code, I suppose wikipedia wouldn't be too hard, but it's late.
 
Originally posted by: stickybytes
Originally posted by: AgaBoogaBoo
5(2+)*3(1-)+4(1+)

Thanks but if this is indeed correct, my java program is doing something wrong.
My program spit out:
52+31-41++*.

For an answer of 49.

Am i doing something wrong? If so, can anyone spot the error?

Thanks.

Are you sure the answer needs to be able to compile and run in java? Because I don't think this is possible in java, since the language does not support postfix operators for arithmetics (unless you are using variables, which I think would still not really answer the question since you could only increment values by one using the ++ operator).
 
Originally posted by: drinkmorejava
If I new the difference I could probably help you with the code, I suppose wikipedia wouldn't be too hard, but it's late.

It's a grammar thing.

Infix means the operator comes between the operands (the plus is between the two numbers being added).

Postfix means the operator comes after the two operands (the plus comes after the two numbers being added).
 
Originally posted by: stickybytes
Originally posted by: AgaBoogaBoo
5(2+)*3(1-)+4(1+)

Thanks but if this is indeed correct, my java program is doing something wrong.
My program spit out:
52+31-41++*.

For an answer of 49.

Am i doing something wrong? If so, can anyone spot the error?

Thanks.


The multiplication sign shouldn't appear at the end... it should come after the - and before the 4. My guess is that there is something wrong with the way you deal with parens. But I'm too lazy to think further about a problem that's solved on the interwebs 🙂

Edit: I assume you're processing a string of (single digit) numbers and using stacks or an expression tree to turn *fix into *fix...?
 
Back
Top