class StackObj
{
private Object[] theStack;
private int maxSize;
private int top;
public StackObj(int s)
{
maxSize = s;
theStack = new Object[maxSize];
top = -1;
}
public void push(Object elem)
{
top++;
theStack[top] = elem;
}
public Object pop()
{
Object result = theStack[top];
top--;
return result;
}
public Object top()
{
return theStack[top];
}
public boolean isFull()
{
return (top == (maxSize-1) );
}
public boolean isEmpty()
{
return (top == -1);
}
public int size()
{
return (top+1);
}
}
Ok so this is a class called STACKOBJ that is a stack of OBJECTS...
THIS IS THE CODE...
Apparently if I try to run System.out.print(evaluatepostfix("123*+9-")); the output is 1 :S[CENTER]public static int evaluatepostfix(String S){ StackObj temp = new StackObj(S.length()); for(int i = 0; i < S.length(); i++){ if(((Integer.parseInt(S.charAt(i) + "")) >= 1) && ((Integer.parseInt(S.charAt(i) + "")) <= 9)){ temp.push(new Integer (Integer.parseInt((S.charAt(i)+"")))); break; }else{ int op1 = ((Integer)temp.pop()).intValue(); int op2 = ((Integer)temp.pop()).intValue(); switch (S.charAt(i)){ case '+': temp.push(new Integer ((op2) + (op1))); break; case '-': temp.push(new Integer ((op2) - (op1))); break; case '*': temp.push(new Integer ((op2) * (op1))); break; case '/': temp.push(new Integer ((op2) / (op1))); break; } } } return ((Integer)temp.pop()).intValue(); }[/CENTER]
HELP???