Skip to content

Conversation

@kamendov-maxim
Copy link
Owner

No description provided.

Comment on lines 38 to 43
char *copyString(char * const string, bool const copyRequired)
{
if (!copyRequired)
{
return string;
}

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

Choose a reason for hiding this comment

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

перенос строки

Comment on lines 1 to 4
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

Choose a reason for hiding this comment

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

опять же stdbool уже есть в .h

Comment on lines 2 to 3
#include <stdio.h>
#include <stdlib.h>

Choose a reason for hiding this comment

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

это тут лишнее

Comment on lines 3 to 6
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

Choose a reason for hiding this comment

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

не нужно подключать лишнее - нам отсюда в заголовчнике нужен только stdbool - остальное подключаем в .c

Comment on lines 7 to 13
typedef enum UserInput
{
appendCommand,
getValueCommand,
checkKeyCommand,
deleteElementCommand
} UserInput;

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)

Choose a reason for hiding this comment

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

разбить на 2 строки

Choose a reason for hiding this comment

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

в строке 80-100 символов максимум

Comment on lines 34 to 81
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;

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

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

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;

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;

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)

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

Copy link
Owner Author

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;

Copy link
Owner Author

Choose a reason for hiding this comment

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

или я не так понял?

Copy link

@Firsov62121 Firsov62121 Dec 3, 2023

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);

Choose a reason for hiding this comment

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

см. выше

Comment on lines 16 to 17
void deleteElement(Dictionary *dictionary, int const key);
void deleteDictionary(Dictionary *dictionary);

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)

Choose a reason for hiding this comment

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

* const везде ниже тоже

Comment on lines 84 to 88
if (value == NULL)
{
printf("Недостаточно памяти\n");
return MEMORY_ERROR;
}

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);

Choose a reason for hiding this comment

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

return

Choose a reason for hiding this comment

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

и тут это не нужно - мы и так выйдем из цикла

Comment on lines 116 to 118
if (*nodeToDelete != right)
{
(*nodeToDelete)->rightChild = right;

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;

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