#includeusing namespace std; #include #include enum Type { OP_SYMBOL, OP_NUM, ADD, SUB, MUL, DIV, }; struct Cell { Type _type; int _value; }; int CountRPN(Cell a[], size_t size) { assert(a != NULL); stack s; while (size--) { if (a->_type == OP_NUM) { s.push(a->_value); } if (a->_type == OP_SYMBOL) { int right = s.top(); s.pop(); int left = s.top(); s.pop(); switch (a->_value) { case ADD: s.push(left+right); break; case SUB: s.push(left-right); break; case MUL: s.push(left*right); break; case DIV: s.push(left/right); break; default: break; } } ++a; } return s.top(); } void TestRPN() { Cell RPNArray[] = { {OP_NUM, 12}, {OP_NUM, 3}, {OP_NUM, 4}, {OP_SYMBOL, ADD}, {OP_SYMBOL, MUL}, {OP_NUM, 6}, {OP_SYMBOL, SUB}, {OP_NUM, 8}, {OP_NUM, 2}, {OP_SYMBOL, DIV}, {OP_SYMBOL, ADD}, }; cout< 创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
标题名称:C++解逆波兰表达式-创新互联
网站URL:http://cxhlcq.com/article/ghhsg.html