Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.

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.

Почти всё хорошо, но надо немного поправить

Comment on lines 13 to 15

Choose a reason for hiding this comment

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

Лучше хранить либо просто height, либо только balance (что сложнее). Потому что вообще-то, красно-чёрные деревья круче АВЛ в частности тем, что там для цвета достаточно одного бита, а для баланса в АВЛ надо два. "А давайте сделаем три (!) тридцатидвухбитные переменные для хранения баланса", решили Вы :) Адельсон-Вельский бы не одобрил.

Choose a reason for hiding this comment

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

В этой задаче ключ уже должен быть строковым по условию

Choose a reason for hiding this comment

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

Suggested change
while(root != NULL)
while (root != NULL)

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Не поправили

Choose a reason for hiding this comment

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

Неудачное название переменной, это ведь не новый корень, это просто узел

Choose a reason for hiding this comment

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

Suggested change
if ((*root)->parent->rightSon == (*root))
if ((*root)->parent->rightSon == *root)

Choose a reason for hiding this comment

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

Suggested change
return;

This comment was marked as resolved.

Choose a reason for hiding this comment

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

"симвовлов", и скобка не закрыта

Comment on lines +14 to +15

Choose a reason for hiding this comment

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

Кажется, rightHeight могло бы быть rightSon->height, и leftHeight соответственно leftSon->height, то есть можно хранить только высоту узла. Что сэкономило бы ещё четыре байта.

Choose a reason for hiding this comment

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

Это, наверное, лучше было назвать updateHeight или что-то такое

Choose a reason for hiding this comment

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

Не поправили

Comment on lines +324 to +328

Choose a reason for hiding this comment

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

Не, оно так не работает :)

Choose a reason for hiding this comment

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

Suggested change
parent->rightSon == (*root) ? attach((*root)->parent, currentRoot, right) : attach((*root)->parent, currentRoot, left);
parent->rightSon == *root ? attach((*root)->parent, currentRoot, right) : attach((*root)->parent, currentRoot, left);

Choose a reason for hiding this comment

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

Suggested change
char* newValue = calloc(strlen((currentRoot)->value) + 1, sizeof(char));
char* newValue = calloc(strlen(currentRoot->value) + 1, sizeof(char));

Choose a reason for hiding this comment

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

Вообще, при удалении узла выделять память --- как-то странно. Можно было просто указатели на уже готовые строки перекинуть. Кстати, ещё есть strdup, которая уменьшает боль с копированием строк

Choose a reason for hiding this comment

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

Так Вы проверяете, что у Вас в корне всё хорошо, а во всём остальном дереве?

Choose a reason for hiding this comment

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

Говорит, что узел удалён, даже если такого нету. Там досадный баг в deleteNode

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.

3 participants