Infix to Postfix with negative number

HER0

New Member
I made an app that allows to convert Infix to Postfix for real numbers (included negative ones). It works perfectly except for those case \[code\]-1-2\[/code\] or \[code\]-2+8-9\[/code\], maybe others. I think that the problem is on the sign '-'. I can't put the whole code. It's very long. This is the part when the char is negative.\[code\]if (ch == '-') { if ((input.charAt(0) == ch) || (input.charAt(j - 1) == '(') || (input.charAt(j - 1) == '-')) temp = temp + ch; else { output = output + temp + " "; temp = ""; gotOper(ch, 1); } }\[/code\]gotOper(ch, 1) is a method that allows to put values on the Stack ; it works perfectly! And I explain more my code: when I have for example \[code\]-1+2\[/code\], when it's '-' I put it into a temporary String, when it's between 0 and 9 or ., the same thing, else (+, -, /, *, $) ($ means square root), I put the temporary String into the \[code\]output\[/code\] and I communicate with the Stack. I can't understand why it displays \[code\]-1-2\[/code\] and \[code\]-2 8-9 +\[/code\] in the cases above. It should be \[code\]-1 2 -\[/code\] and \[code\]-2 8 + 9 -\[/code\]
 
Back
Top