Skip to content

Commit

Permalink
lab2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-anastasiia committed Sep 20, 2024
1 parent 01f79ac commit 569ea9f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lab2CPP/lab2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ int evaluate_example(const std::string& example) {

else if (example[i] == ')') {
while (!stack_empty(operators) && stack_get(operators) != '(') {
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val2 = stack_get(values);
stack_pop(values);
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val1 = stack_get(values);
stack_pop(values);
char op = stack_get(operators);
Expand All @@ -66,8 +68,10 @@ int evaluate_example(const std::string& example) {

else if (example[i] == '+' || example[i] == '-' || example[i] == '*' || example[i] == '/') {
while (!stack_empty(operators) && precedence(stack_get(operators)) >= precedence(example[i])) {
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val2 = stack_get(values);
stack_pop(values);
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val1 = stack_get(values);
stack_pop(values);
char op = stack_get(operators);
Expand All @@ -80,8 +84,10 @@ int evaluate_example(const std::string& example) {


while (!stack_empty(operators)) {
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val2 = stack_get(values);
stack_pop(values);
if (stack_empty(values)) throw std::runtime_error("Invalid expression");
int val1 = stack_get(values);
stack_pop(values);
char op = stack_get(operators);
Expand Down

0 comments on commit 569ea9f

Please sign in to comment.