public String infixToPostfix(){
String delims = "+-*/() ";
StringTokenizer strToken = new StringTokenizer(jtfInfix.getText(), delims, true);
Stack<Character> stack = new Stack<>();
String postfix = "";
while(strToken.hasMoreTokens()) {
String token = strToken.nextToken().trim();
char c = token.charAt(0);
//checks to see if the input is a integer
if(Character.isDigit(c))
postfix += c;
//checks for open Parenthesis
else if(c == '(')
stack.push(c);
//checks for closed Parenthesis
else if(c == ')') {
while (!stack.isEmpty() && stack.peek() != '(')
postfix += stack.pop() + " ";
if (!stack.isEmpty() && stack.peek() == '(')
stack.pop();
}
else if(delims.indexOf(c) != -1) {
if((c == '-' || c =='+') && (!stack.isEmpty() && (stack.peek() == '*' || stack.peek() == '/')))
postfix += stack.pop() + " ";
else if((c == '*' || c =='/') && (!stack.isEmpty() && (stack.peek() == '-' || stack.peek() == '+')))
stack.push(c);
else
postfix += c + " ";
}
}
while (!stack.isEmpty()) {
postfix += stack.pop() + " ";
}
return postfix.trim();
}
929441123200548954