# Thread: Just a postfix clarification.

1. ## Just a postfix clarification.

With negative numbers ( using a unary '-' ), such as the examples:

-6(5+3)/2
(5+3)*(-2+1)

How is this converted to postfix? I haven't really tackled the issue too deep but it seems like it may interfere with a minus in postfix. I'd wager a guess that these would be converted as:

6-53+*2/
53+2-1+*

But in evaluating the second one, I could see myself ending up with a loose end at 7*. I hope you're following. If you know how these are handled, please tell me. Perhaps I should put parenthesis in the postfix such as:

(-6)52+*2/
53+(-2)1+*

Any suggestion or answers on how this is handled? The way my program is set up, it's currently accepting a string, converting to a postfix string and evaluated to a long. Thanks.

2. Another possiblility I'm considering is that in the postfix string the instance unary '-' is replaced with another character. Perhaps a tilde or something similar.

EDIT: Actually I think I got it. Since I'll have to add spaces to accomedate two digit numbers, I'll just have to do a check in converting to postfix to see if a '-' is unary and then just not add a space for that. Example:

Code:
```-34(16+22)/2          /* infix */
-34 16 22 + * 2 /     /* postfix */```
If you can think of something better or you think this is the best way, some input would be great.

3. (5+3)*(-2+1)

How is this converted to postfix? I haven't really tackled the issue too deep but it seems like it may interfere with a minus in postfix.
Erm yes, I was having similar problemos. Postfix, doesn' t provide a fully working model of everything you'd like it to do. So a little bit of tinkering is needed.

But before you look into that, these two sources are absolute gems, in regards to Postfix notation.

http://www.spsu.edu/cs/faculty/bbrow...tures/postfix/
http://www.qiksearch.com/articles/cs...ix-evaluation/

And when you do actually get round to it. You'll be needing to use...

1. The stack (Of course)
2. The STL string class
3. Vectors...much better than arrays
4. Tokens.