-
Notifications
You must be signed in to change notification settings - Fork 0
Balance brackets #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Balance brackets #15
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Уважаемые люди рекомендуют сложные условия в отдельные функции выносить
| } | ||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, stdlib тут так и не пригодился
| const char sixthIncorrectExpressionFromParentheses[250] = "{{}}((("; | ||
| const char seventhIncorrectExpressionFromParentheses[250] = "("; | ||
|
|
||
| return checkCorrectOrderBrackets(firstCorrectExpressionFromParentheses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем так мучиться? Можно просто
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Думаю, что char-овский стек не подойдёт другим задачам. Тут лучше было сделать int, а в алгоритме проверки скобок кастать всё к чему нужно
yurii-litvinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В целом всё хорошо, так что зачтена
| return paretheses == ')' || paretheses == '}' || paretheses == ']'; | ||
| } | ||
|
|
||
| bool openingAndClosingOfTheSameType(char openingParetheses, char closingParetheses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, что лучше бы подошло "notOpeningAndClosingOfTheSameType", или в самой функции поправить и в месте вызова "!" писать
| push(&head, expressionFromParentheses[counter], &error); | ||
| if (error == 2) | ||
| { | ||
| *errorCode = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кстати, можно было тогда уж в push сразу errorCode передавать :) Но тогда стоило бы его сделать нулём в начале функции и гарантировать, что как только он не 0, мы тут же выходим.
| deleteStack(&head); | ||
| return true; | ||
| } | ||
| *errorCode = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы тут 0 оставил. Функция корректно отработала, просто скобочная последовательность не корректна (на то Вы true/false и возвращаете)
| push(&head, '1', &error); | ||
| if (error == 2) | ||
| { | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут бы тоже как-то позаботиться о памяти, выделенной уже под стек. С другой стороны, если сам стек не работает, то нет гарантии, что и память за собой он подчистит, но стоит всё-таки хотя бы попытаться.
No description provided.