Conversation
fixed bugs
| #include <stdbool.h> | ||
|
|
||
| // Function to check the correct position of the brackets | ||
| bool checkCorrectOrderBrackets(const char* expressionFromParentheses�); No newline at end of file |
There was a problem hiding this comment.
| bool checkCorrectOrderBrackets(const char* expressionFromParentheses�); | |
| bool checkCorrectOrderBrackets(const char* expressionFromParentheses); |
| char topOfTheStack = pop(&head, &error); | ||
| if (error == 1) | ||
| { | ||
| return false; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| if ((topOfTheStack != '(' && expressionFromParentheses[counter] == ')') | ||
| || (topOfTheStack != '{' && expressionFromParentheses[counter] == '}') | ||
| || (topOfTheStack != '[' && expressionFromParentheses[counter] == ']')) |
There was a problem hiding this comment.
Уважаемые люди рекомендуют сложные условия в отдельные функции выносить
| } | ||
| if (isEmpty(head)) | ||
| { | ||
| return true; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| @@ -0,0 +1,40 @@ | |||
| #include "BalanceBrackets.h" | |||
| #include "../../Stack/Stack/Stack.h" | |||
| #include <stdlib.h> | |||
There was a problem hiding this comment.
Кажется, stdlib тут так и не пригодился
| const char sixthIncorrectExpressionFromParentheses[250] = "{{}}((("; | ||
| const char seventhIncorrectExpressionFromParentheses[250] = "("; | ||
|
|
||
| return checkCorrectOrderBrackets(firstCorrectExpressionFromParentheses) |
There was a problem hiding this comment.
Зачем так мучиться? Можно просто
| return checkCorrectOrderBrackets(firstCorrectExpressionFromParentheses) | |
| return checkCorrectOrderBrackets("((15 - x) - (13 + 45) * ( 1 0 - 1 6))") |
Stack/Stack/Stack.h
Outdated
| // Structure for implementing a stack consisting of a value and a pointer to the next element | ||
| typedef struct Stack | ||
| { | ||
| char value; |
There was a problem hiding this comment.
Думаю, что char-овский стек не подойдёт другим задачам. Тут лучше было сделать int, а в алгоритме проверки скобок кастать всё к чему нужно
yurii-litvinov
left a comment
There was a problem hiding this comment.
В целом всё хорошо, так что зачтена
| return paretheses == ')' || paretheses == '}' || paretheses == ']'; | ||
| } | ||
|
|
||
| bool openingAndClosingOfTheSameType(char openingParetheses, char closingParetheses) |
There was a problem hiding this comment.
Кажется, что лучше бы подошло "notOpeningAndClosingOfTheSameType", или в самой функции поправить и в месте вызова "!" писать
| push(&head, expressionFromParentheses[counter], &error); | ||
| if (error == 2) | ||
| { | ||
| *errorCode = 2; |
There was a problem hiding this comment.
Кстати, можно было тогда уж в push сразу errorCode передавать :) Но тогда стоило бы его сделать нулём в начале функции и гарантировать, что как только он не 0, мы тут же выходим.
| deleteStack(&head); | ||
| return true; | ||
| } | ||
| *errorCode = 1; |
There was a problem hiding this comment.
Я бы тут 0 оставил. Функция корректно отработала, просто скобочная последовательность не корректна (на то Вы true/false и возвращаете)
| push(&head, '1', &error); | ||
| if (error == 2) | ||
| { | ||
| return false; |
There was a problem hiding this comment.
Тут бы тоже как-то позаботиться о памяти, выделенной уже под стек. С другой стороны, если сам стек не работает, то нет гарантии, что и память за собой он подчистит, но стоит всё-таки хотя бы попытаться.
No description provided.