# Thread: Writing in postfix notation

1. ## Writing in postfix notation

For a lab we must convert an infix expression to a postfix one that is devoid of parentheses.

Like if I entered (3 + 5) the postfix expression is 35+

However, what if I do (19 + 2)? It certainly is not 192+, for that would make 111, which just... isn't right. And we can't do (19)2+ I assume because the problem clearly states that parenthesis cannot be used. What's the official way, here?

2. You're probablly reading the problem wrong. You can't do what you want to do.

EDIT: You are talking about compile-time, right? Or are you saying that you want someone to input something through IO? You can't overload operators to make 35+ do 3 + 5 because there is no postfix operator +

If you mean via IO then I don't see what the problem is. Just use a space.

3. I think you misread the question

4. The user inputs a string of an infix expression and the equation inputted into the string is converted to postfix and evaluated

5. why not just put spaces or commas in between the numbers? so 3+5 -> 3,5+ or 3 5+, and 19 + 2 -> 19,2+ or 19 2+

6. Yeah, like i said

35+

is not a postfix addition expression because it has only one operand

you have to separate them by spaces.

IE

3 5 +

7. Ah, I see :P

Yeah, in our class 3 + 5 is written as 35+

8. Well what you can do is enter all those character into a char array infix, then convert it into a postfix expression and put it into char array postfix, then evaluate that postfix expression using the postfix array.

I did the same thing, and I used a Stack data structure to solve it, with a dynamic char array to hold my postfix expression.

Also you need to put spaces netween your postfix expression, because it makes it easier to read, for example:

192+ --> is this (19 + 2) or (1 + 92) ?

so you write it:

19 2 +