Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.

#include <stdbool.h>

// Function to check the correct position of the brackets
bool checkCorrectOrderBrackets(const char* expressionFromParentheses�); No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines 25 to 27
if ((topOfTheStack != '(' && expressionFromParentheses[counter] == ')')
|| (topOfTheStack != '{' && expressionFromParentheses[counter] == '}')
|| (topOfTheStack != '[' && expressionFromParentheses[counter] == ']'))

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.

@@ -0,0 +1,40 @@
#include "BalanceBrackets.h"
#include "../../Stack/Stack/Stack.h"
#include <stdlib.h>

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем так мучиться? Можно просто

Suggested change
return checkCorrectOrderBrackets(firstCorrectExpressionFromParentheses)
return checkCorrectOrderBrackets("((15 - x) - (13 + 45) * ( 1 0 - 1 6))")

// Structure for implementing a stack consisting of a value and a pointer to the next element
typedef struct Stack
{
char value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, что char-овский стек не подойдёт другим задачам. Тут лучше было сделать int, а в алгоритме проверки скобок кастать всё к чему нужно

Copy link

@yurii-litvinov yurii-litvinov left a 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)

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;

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;

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут бы тоже как-то позаботиться о памяти, выделенной уже под стек. С другой стороны, если сам стек не работает, то нет гарантии, что и память за собой он подчистит, но стоит всё-таки хотя бы попытаться.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants