-
Notifications
You must be signed in to change notification settings - Fork 0
Number1 #34
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?
Conversation
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.
Местоположение этих проектов как-то против принятых в остальном репозитории соглашений.
Number1/Number1/Main.c
Outdated
| { | ||
| printf("����������, ������� ����\n"); | ||
| int key = 0; | ||
| const int firstScanfResilt = scanf("%d", &key); |
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.
firstScanfResult, тут и ниже (в нескольких местах)
Number1/Number1/Main.c
Outdated
| } | ||
| printf("����������, ������� ������, ������� ������ ��������\n"); | ||
| char string[100] = {'\0'}; | ||
| const int secondScanfResult = scanf("%s", string); |
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.
scanf_s лучше, у нас ведь входной буфер ограничен 99 символами, о чём мы пользователя даже не предупреждаем, кстати
| } | ||
| } | ||
|
|
||
| void zig(Node* x) |
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.
В этой задаче дерево не обязательно должно быть сбалансированным, можно было сэкономить кучу сложности. Хотя раз мы всё равно на паре балансировку написали, то почему нет
Tree/Tree/Tree.c
Outdated
| char* copyValue = calloc(100, sizeof(char)); | ||
| if (copyValue == NULL) | ||
| { | ||
| return NULL; |
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.
Это не очень хорошо работает с tree = addNode(tree, key, string); из main-а. Потому что тогда в main надо писать что-то в духе
Tree *temp = addNode(tree, key, string);
if (temp == NULL)
{
deleteTree(tree);
return -1;
}
tree = temp;Что слишком утомительно. Лучше поступать как scanf — сообщать об ошибке, но само дерево не трогать.
Tree/Tree/Tree.c
Outdated
| if (root == NULL) | ||
| { | ||
| return false; | ||
| } | ||
| return true; |
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.
Так писать нельзя :)
Tree/Tree/Tree.c
Outdated
| } | ||
|
|
||
|
|
||
| Node* addNode(Node* root, int key, 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.
Думаю, что const char *value, мы ведь не собираемся его менять тут. Это позволит компилятору не ругаться на строковые литералы при вызове функции.
Tree/Tree/Tree.c
Outdated
| if (root->parent->rightSon == root) | ||
| { | ||
| root->parent->rightSon = NULL; | ||
| root->parent = NULL; |
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. Но вообще, мы сейчас root удалим, о значениях его полей беспокоиться незачем. Всё равно что хорошенько прибраться в доме перед его сносом — можно, но зачем?
Tree/Tree/Tree.c
Outdated
| { | ||
| if (root->parent == NULL) | ||
| { | ||
| Node* j = root->leftSon; |
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.
Вообще, кажется, стайлгайд запрещает имена переменных короче четырёх символов
Tree/Tree/Tree.c
Outdated
| root->leftSon->parent = root->parent; | ||
| if (root->parent->leftSon == root) | ||
| { | ||
| root->parent->leftSon = root->leftSon; | ||
| } | ||
| else if (root->parent->rightSon == root) | ||
| { | ||
| root->parent->rightSon = root->leftSon; | ||
| } |
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.
Опять-таки, что-то такое делает attach, а если нет, то стоит это вынести в функцию. Потому что очень уж сложно получилось
| break; | ||
| } | ||
| tree = deleteNode(tree, key); | ||
| printf("�������� �������\n"); |
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.
Даже если удаление не удалось :)
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.
Остались только "косметические" замечания, так что зачтена.
Homework №7/Tree/Tree/Tree.h
Outdated
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.
Не совсем, и непонятно ни по названию, ни по комментарию, что она делает. Тем более что у дерева может быть много инвариантов (у Вас, например, что node->parent == NULL || node->parent->leftSon == node || node->parent->rightSon == node — это тоже инвариант). Интересно, что инвариант "является деревом поиска" функция как раз не проверяет — она не смотрит, что больший ключ справа :) Скорее, это проверка, что узел с secondKey является сыном узла firstKey, это и стоило отразить хотя бы в комментарии (и может даже назвать функцию isChild).
Homework №7/Tree/Tree/Tree.c
Outdated
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.
| } | |
| Node* addNode(Node* root, int key, const char* value, Error* error) | |
| } | |
| Node* addNode(Node* root, int key, const char* value, Error* error) |
Homework №7/Tree/Tree/Tree.c
Outdated
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.
Я б её назвал currentNode. Хотя это, безусловно, корень текущего поддерева, но кажется, что мы используем её просто для спуска по дереву.
Homework №7/Tree/Tree/Tree.c
Outdated
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.
Можно было просто
| Node* searchResult = search(root, key); | |
| return searchResult != NULL; | |
| return search(root, key) != NULL; |
Хотя Ваш вариант немного удобнее для отладки.
Homework №7/Tree/Tree/Tree.c
Outdated
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 ((*root)->parent->rightSon == (*root)) | |
| if ((*root)->parent->rightSon == *root) |
Homework №7/Tree/Tree/Tree.c
Outdated
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; |
No description provided.