A String variable references a mathematical equation. Within a method called convertToPostFix(String s), I am analyzing each character in the equation as follows:
Within this method, I loop through the entire string and push digits to the stack until an operator is found, if no operator is currently in the stack, push(operator). If a right parenth is found, pop all the elements in the stack to an output string. Alternatively, if an operator is found to exist in the stack already, I check the stack precedence with the following method:
I'm really not sure if I'm doing this correctly, or if I am way off. My output is incorrect and looks something like this : (1053
Is this the correct use of the stack?
It's really hard to follow the logic in your code. The algorithm could probably be simpler. Also, your switches don't make much sense. One always returns true, and the other always returns false. Not much point to a switch statement then...
Here's a small piece of code that will make reading your input *much* easier. It breaks up your input string in tokens that are either operators, parentheses, or other values.
operatorTokens is a collection of Strings representing your operators.
Ruth Stout was famous for gardening naked. Just like this tiny ad: