Algo lab/templates/postfix
ไปยังการนำทาง
ไปยังการค้นหา
Comments:
- Since the stack has to keep doubles, we change ValueType to double.
- We use iomanip to set precision.
- We use function stod to convert strings to doubles. (s-to-d)
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string buffer;
do {
cin >> buffer;
if(buffer.at(0) == '=') {
break;
} else if((buffer.at(0) >= '0') && (buffer.at(0) <= '9')) {
double val = stod(buffer);
// *****************************
// insert val into the top of the stack
} else {
// *****************************
// buffer is an operator.
// your code here
}
} while(true);
cout << fixed << setprecision(4) << head->val << endl;
}