Similar as using two stacks, the idea is to maintain two queues for both numbers and operands:

- if (*) (/) is met, keep pushing the numbers and operands into the queues.
- if (+) (-) is met, collect numbers/operands from the 2 queues and do the calculation, until the queue is empty.

```
int calculate(string s) {
s.push_back('+'); //append "+" sign to make sure the last loop is run
int output = 0;
char prev = '+'; // initial condition
queue<char> op; // queue that holds the operants
queue<int> num; // queue that holds the numbers
int tmp = 0;
for(int i=0; i<s.size(); i++){
if(isdigit(s[i])) {
tmp = 10*tmp + (s[i]-'0');
continue;
}
if(!isspace(s[i])){ // skip the space
num.push(tmp);
if(s[i] == '+' || s[i] == '-'){
int tmp1 = num.front();
num.pop();
while(!op.empty()){
tmp1 = (op.front() == '*') ? tmp1*num.front() : tmp1/num.front();
num.pop();
op.pop();
}
output = (prev == '+') ? output + tmp1: output - tmp1;
prev = s[i];
}
else{
op.push(s[i]);
}
tmp = 0;
}
}
return output;
}
```