When you pop, place the value in a string and compare it with the String "add":
for example (not exaclty java code because i don;t remember by heart the right syntax)
String s=stack.pop();
if (s.equals("add")) {
int i=Integer.parseInt( stack.pop() );
int j=Integer.parseInt( stack.pop() );
int res=i+j;
stack.push( String.valueOf(res) );
} else if (s.equals("sub")) {
//do something
} else if (s.equals("mult")) {
//do something
} else if (s.equals("div")) {
//do something
} else {
stack.push(s);//it puts it back because it is (probably) a number
}
This is just a general idea. I don't know what exactly you want to do and how you want to push or pop things in the stack
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448