Conversation
hw7/mergeSort/list.c
Outdated
| free(list); | ||
| return NULL; | ||
| } | ||
| list->head->next = NULL; |
There was a problem hiding this comment.
А calloc и так это гарантирует, так что эта строка не сделает ничего
| } | ||
| Position current = list->head; | ||
| while (current != NULL) { | ||
| printf("%s %s\n", current->name, current->phone); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
hw7/mergeSort/list.h
Outdated
| List* createList(void); | ||
|
|
||
| // function for adding an element | ||
| void addContact(List* list, char* name, char* phone); |
There was a problem hiding this comment.
Лучше было бы const char* name, const char* phone. Как минимум, это позволит без боли и страха использовать строковые литералы в качестве аргументов
hw7/mergeSort/list.h
Outdated
| void printList(List* list); | ||
|
|
||
| // removes the entire list and frees memory | ||
| void removeList(List* list); |
There was a problem hiding this comment.
Лучше ** и сбрасывать указатель в NULL, чтобы у вызывающего не оставалось висячего указателя при удалении
hw7/mergeSort/list.h
Outdated
| void removeList(List* list); | ||
|
|
||
| // function for getting the name of the transmitted contact | ||
| char* getName(ListElement* element); |
hw7/mergeSort/mergeSort.h
Outdated
| // splits the list into parts | ||
| void split(List* source, List** front, List** back); | ||
|
|
||
| // sorts a list using a merge method | ||
| List* mergeSort(List* list, SortType sortType); | ||
|
|
||
| // combines two sorted lists into one, following the specified sort type | ||
| List* merge(List* first, List* second, SortType sortType); No newline at end of file |
There was a problem hiding this comment.
Из этих трёх функций только одна реально тут нужна, остальные в .c-шнике только должны быть
hw7/mergeSort/reader.c
Outdated
|
|
||
| #include <stdio.h> | ||
|
|
||
| void reader(const char* filename, List* list) { |
There was a problem hiding this comment.
Функуии именуются как глаголы в повелительной форме
hw7/mergeSort/reader.c
Outdated
| FILE* file = fopen(filename, "r"); | ||
| if (file == NULL) { |
There was a problem hiding this comment.
Путать пробелы и табуляции для отступов — страшное преступление :) Поправьте тут.
hw7/mergeSort/reader.c
Outdated
| char name[50]; | ||
| char phone[20]; |
There was a problem hiding this comment.
Массивы тоже надо инициализировать
hw7/mergeSort/test.c
Outdated
| #include <stdbool.h> | ||
| #include <string.h> | ||
|
|
||
| bool testSplit() { |
There was a problem hiding this comment.
Тестируем всегда только внешнее поведение, иначе тесты будут завязаны на особенности реализации модуля
yurii-litvinov
left a comment
There was a problem hiding this comment.
Всё ок — ещё один мемлик есть, но с очевидным фиксом, так что зачтена
| List* first = NULL; | ||
| List* second = NULL; | ||
| split(list, &first, &second); | ||
|
|
There was a problem hiding this comment.
После этого list не нужен, его можно было бы тут удалить (и даже нужно, потому что иначе его так никто и не удалит)
No description provided.