Skip to content

Comments

Стек и очередь: Продвинутый баланс скобок#6

Open
imaxde wants to merge 4 commits intomainfrom
braces_balance
Open

Стек и очередь: Продвинутый баланс скобок#6
imaxde wants to merge 4 commits intomainfrom
braces_balance

Conversation

@imaxde
Copy link
Owner

@imaxde imaxde commented Dec 22, 2025

No description provided.

@imaxde imaxde requested a review from WoWaster December 22, 2025 01:47
Copy link
Collaborator

Choose a reason for hiding this comment

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

Вообще в задаче написано, что стек должен быть реализован в отдельной ветке, от которой отводятся другие две ветки. Это придётся сделать.

struct Stack* next;
};

struct Stack* push(struct Stack* stack, int value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Дизайн интересный, и был бы очень хорош в функциональном языке, но в Си приводит к ошибкам. Лучше сделать отдельную структуру для элемента стека и стуктуру-обёртку, которая будут передаваться в функции, тогда пользователю не нужно будет знать, что у него ничего о внутреннем устройстве стека

Comment on lines +21 to +24
struct Stack* pop(struct Stack* stack, int* value)
{
if (stack == NULL)
return NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Не лучшее решение. В такой реализации мы не отличим был ли пуст стек, или мы забрали последний элемент из него.

Когда будете переписывать, Вам будет полезно знать про две стратегии реализации pop и peek.

  1. Проверять пустоту стека прямо в функции и тогда применять errorCode/присваивание по указателю (как здесь)
  2. Заставить пользовавателя проверять в своём коде, что стек не пуст

Comment on lines +40 to +43
struct Stack* new(void)
{
return NULL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

А правда в таком случае в этой функции вообще есть смысл? И, кстати, лучше не использовать new и delete, потому что это ключевые слова C++ и инструменты могут на них орать.

int numTests = sizeof(tests) / sizeof(tests[0]);

for (int i = 0; i < numTests; i++) {
printf("String: \"%s\" is %s\n", tests[i], isBalanced(tests[i]) ? "сбалансирована" : "не сбалансирована");
Copy link
Collaborator

Choose a reason for hiding this comment

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

:) Интересный русско-английский у Вас вывод

return balanced;
}

int main(void) {
Copy link
Collaborator

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