can anyone convert this infix expression to postfix

stickybytes

Golden Member
Sep 3, 2003
1,043
0
0
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.
 

drinkmorejava

Diamond Member
Jun 24, 2004
3,567
7
81
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.
 

KingGheedora

Diamond Member
Jun 24, 2006
3,248
1
81
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).
 

KingGheedora

Diamond Member
Jun 24, 2006
3,248
1
81
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).
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
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...?