Reverse Polish Notation

Im having trouble grasping the concept of RPN. I have to read it and evaluate using stack

 ``1234567`` `````` // im reading it in as a string string prefix; cout << "Enter: "; cin >> prefix; // then I convert it to integer atoi(prefix.c_str()) ``````

but then how do i differentiate from a number and an operand?
Any help would be appreciated
Last edited on
so nothing?
lookt at the reference of ctype, like this:

http://www.cplusplus.com/reference/cctype/isdigit/

you need a loop for your string `prefix`:
 ``12345678`` ``````for(size_t i = 0; i < prefix.size(); ++i) { if(isdigit(prefix[i])) ... else if('+' == prefix[i]) ... else }``````
ok thanks for pushing me in the right direction coder777
 ``123456789101112`` ``````if(isdigit(prefix[i])) { stack.push(prefix); } else if('+' == prefix[i]) { operandstack.push(prefix); } else if('-' == prefix[i]) . . .``````

would it be something like that?
can someone help me convert this to take n amount of numbers.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445`` ``````double value1; double value2, value3; if('+' == str[i]) { value2 = calculate.top(); calculate.pop(); value1 = calculate.top(); calculate.pop(); value3 = calculate.top(); calculate.pop(); calculate.push(value1 + value2 + value3); cout << "no" ; } else if('-' == str[i]) { value2 = calculate.top(); calculate.pop(); value1 = calculate.top(); calculate.pop(); calculate.push(value1- value2); } else if( '*'== str[i]) { value2 = calculate.top(); calculate.pop(); value1 = calculate.top(); calculate.pop(); calculate.push(value1*value2); } else if( '/' == str[i]) { value2 = calculate.top(); calculate.pop(); if (value2 == 0) {undefined = true;} else value1 = calculate.top(); calculate.pop(); calculate.push(value1 / value2); } ``````
Topic archived. No new replies allowed.