this is what i got done so far but need help desperatly
public class postfix{
private
String postfixString, outputString;
private boolean isOperator(char c){
return (c=='+'||c=='-'||c=='*'||c=='/');
}
private boolean is Space(char c){
return(c=='');
}
public void interpretPostfix(){
Stack evalStack = new Stack();
double leftOperand, rightOperand;
char c;
StringTokenizer parser = new String Tokenizer(postfixString,"+-*/", true);
while(parser.hasMoreTokens()){
String token = parser.nextToken();
c = token.charAt(0);
if ((token.lenth()==1)&&isOperator(c){
rightOperand = ((Double) evalStack.pop()).doubleValue();
leftOperand = ((Double) evalStack.pop()).doubleValue();
switch (c){
case '+':evalStack.push(newDouble (leftOperand+rightOperand));
break;
case '-':evalStack.push(newDouble (leftOperand-rightOperand));
break;
case '*':evalStack.push(newDouble (leftOperand*rightOperand));
break;
case '/':evalStack.push(newDouble (leftOperand/rightOperand));
break;
default:
break;
}
}else if ((token.length()==1)&&isSpace(c)){
;
}else{
evalStack.push(Double.valueOf(token));
}
}
output("Value of postfix expression =" + evalStack.pop());
}
private void output(String s){
outputString = s;
}
public void setInput(String input){
postfixString = input;
}
public String getOutput(){
return outputString;
}
------------------------------------------------------------------------------
//stack code
public class Stack{
private int count;
private int capacity;
private int capacityIncrement;
private Object[]itemArray;
public Stack(){
count =0;
capacity = 10;
capacityIncrement = 5;
itemArray = new Object[capacity];
}
public boolean empty(){
return (count ==0);
}
public void push(Object X){
if (count==capacity){
capacity+=capacityIncrement;
Object[]tempArray = new Object[capacity];
for(int i = 0; i<count; i++){
tempArray[i] = itemArray[i];
}
itemArray = tempArray;
}
itemArray[count++] = X;
}
public Object pop(){
if(count ==0){
return null;
}else{
return itemArray[--count];