Skip to content
Snippets Groups Projects
Commit 84607458 authored by Jacek Galowicz's avatar Jacek Galowicz
Browse files

Merge branch 'master' into 'master'

Simplified parsing logic

See merge request jg943598/rpn_calculator!6
parents 8e85f08f 736a2a28
No related branches found
No related tags found
No related merge requests found
......@@ -55,8 +55,7 @@ int evaluate(const std::string &s) {
for (char c : s) {
if (std::isdigit(c)) {
stack.push(c - '0');
} else {
if (stack.size() >= 2 ) {
} else if (stack.size() >= 2 ) {
iter = map.find(c);
if (iter != map.end()) {
a = stack.top();
......@@ -67,9 +66,8 @@ int evaluate(const std::string &s) {
} else {
throw std::invalid_argument("Invalid character found.");
}
} else {
throw std::invalid_argument("Invalid number of digits.");
}
} else {
throw std::invalid_argument("Invalid number of digits.");
}
}
if (stack.size() > 1 || stack.size() == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment