-
Couldn't load subscription status.
- Fork 0
Дерево поиска #19
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?
Дерево поиска #19
Conversation
| char *copyString(char * const string, bool const copyRequired) | ||
| { | ||
| if (!copyRequired) | ||
| { | ||
| return 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.
убрать флаг copyRecuired - пусть его проверяет вызывающий код, эта логика не относится к строкам
| #include <string.h> | ||
|
|
||
| char *getString(size_t * const len, FILE * filename, char const endOfLine); | ||
| char *copyString(char * const string, bool const copyRequired); 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.
перенос строки
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <stdbool.h> | ||
| #include <string.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.
опять же stdbool уже есть в .h
| #include <stdio.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.
это тут лишнее
| #include <stdio.h> | ||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <string.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.
не нужно подключать лишнее - нам отсюда в заголовчнике нужен только stdbool - остальное подключаем в .c
| typedef enum UserInput | ||
| { | ||
| appendCommand, | ||
| getValueCommand, | ||
| checkKeyCommand, | ||
| deleteElementCommand | ||
| } UserInput; |
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.
вынести в отдельный заголовочник - использовать тут и в main
| deleteElementCommand | ||
| } UserInput; | ||
|
|
||
| static bool testCase(size_t testLen, UserInput const *const testCommands, int const *const keys, char **values, char const **charAnswers, bool const *const boolAnswers) |
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.
разбить на 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.
в строке 80-100 символов максимум
| dictionaryErrorCode = append(dictionary, keys[currentKey], values[currentValue], true); | ||
| if (dictionaryErrorCode != ok) | ||
| { | ||
| return false; | ||
| } | ||
| ++currentKey; | ||
| ++currentValue; | ||
| break; | ||
| } | ||
|
|
||
| case getValueCommand: | ||
| { | ||
| if (strcmp(getValue(dictionary, keys[currentKey]), charAnswers[currentAnswer]) != 0) | ||
| { | ||
| return false; | ||
| } | ||
| ++currentKey; | ||
| ++currentAnswer; | ||
| break; | ||
| } | ||
|
|
||
| case checkKeyCommand: | ||
| { | ||
| if (keyCheck(dictionary, keys[currentKey]) != boolAnswers[currentBool]) | ||
| { | ||
| return false; | ||
| } | ||
| ++currentKey; | ||
| ++currentBool; | ||
| break; | ||
| } | ||
|
|
||
| case deleteElementCommand: | ||
| { | ||
| deleteElement(dictionary, keys[currentKey]); | ||
| if (keyCheck(dictionary, keys[currentKey])) | ||
| { | ||
| return false; | ||
| } | ||
| ++currentKey; | ||
| break; | ||
| } | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
| } | ||
| 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.
опять же везде явно перед выходом чистить память
| bool testCase3 = testCase(4, testCommands3, testKeys3, testValues3, charAnswers3, boolAnswers3); | ||
|
|
||
| return testCase1 && testCase2 && testCase3; | ||
| } 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.
перенос строки добавить в конец файла
|
|
||
| #include "../binarySearchTree/binarySearchTree.h" | ||
|
|
||
| const bool test(void); 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.
тут тоже
| Node *newNode = (Node *)calloc(1, sizeof(Node)); | ||
| if (newNode == NULL) | ||
| { | ||
| return memoryError; |
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.
не почистили valueCopy
| *nodeToDelete = getMinNode(right); | ||
| if (*nodeToDelete != right) | ||
| { | ||
| (*nodeToDelete)->rightChild = right; |
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.
мы потомку right в качестве правого узла назначаем right - получаем цикл!
| return searchNode((&(*root)->rightChild), key); | ||
| } | ||
|
|
||
| DictionaryErrorCode append(Dictionary *dictionary, int const key, char *const value, bool const copyRequired) |
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.
Dictionary * const
const char * const
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 сделать const, будет на эту строку ругаться
char *valueCopy = 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.
или я не так понял?
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.
согласен, был неправ
| Dictionary *createDictionary(void); | ||
| char *getValue(Dictionary *const dictionary, const int key); | ||
| bool keyCheck(Dictionary *const dictionary, const int key); | ||
| DictionaryErrorCode append(Dictionary *dictionary, int const key, char *const value, bool const copyRequired); |
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.
см. выше
| void deleteElement(Dictionary *dictionary, int const key); | ||
| void deleteDictionary(Dictionary *dictionary); |
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 тут и в .c
|
|
||
| const size_t commandsCount = 5; | ||
|
|
||
| static void scanfCheck(int scanned, Dictionary *dictionary) |
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 везде ниже тоже
| if (value == NULL) | ||
| { | ||
| printf("Недостаточно памяти\n"); | ||
| return MEMORY_ERROR; | ||
| } |
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.
память не почистили
| { | ||
| printf("Завершение работы\n"); | ||
| deleteDictionary(dictionary); | ||
| exit(PROGRAM_FINISHED_CORRECTLY); |
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
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 (*nodeToDelete != right) | ||
| { | ||
| (*nodeToDelete)->rightChild = right; |
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.
тут всё ещё ошибка - никто не гарантирует, что rightChild буден NULL у минимального узла
не надо его (minNode) удалять из правого поддерева - достаточно в nodeToDelete положить right +
(minNode)->leftChild = left;
No description provided.