public class InfixToPostfix {
    public String pretvori(String ulaz) {
	Stog stog=new Stog(ulaz.length());
	StringBuffer novi=new StringBuffer(ulaz.length());
	Character c,top;

	for (int i=0;i<ulaz.length();i++) {
	    c=new Character(ulaz.charAt(i));
	    top=(Character)stog.top();
	    switch (c.charValue()) {
		case '(':
		    stog.push(c);
		    break;
		case '+':
		case '-':
		    while (!stog.isempty() && top.charValue()!='(') {
			novi.append(top);
			stog.pop();
			top=(Character)stog.top();
		    }
		    stog.push(c);
		    break;
		case '*':
		case '/':
		case '%':
		    while (!stog.isempty() && top.charValue()!='(' && top.charValue()!='+' && top.charValue()!='-') {
			novi.append(top);
			stog.pop();
			top=(Character)stog.top();
		    }
		    stog.push(c);
		    break;
		case '^':
		    while (!stog.isempty() && top.charValue()=='^') {
			novi.append(top);
			stog.pop();
			top=(Character)stog.top();
		    }
		    stog.push(c);
		    break;
		case ')':
		    while (!stog.isempty() && top.charValue()!='(') {
			novi.append(top);
			stog.pop();
			top=(Character)stog.top();
		    }
		    stog.pop();
		    break;
		default:
		    novi.append(c);
	    }
	}
	while (!stog.isempty()) {
	    novi.append(stog.top());
	    stog.pop();
	}

	return novi.toString();
    }
}
