Skip to content

Comments

mergeSort#28

Open
Andrw-404 wants to merge 7 commits intomainfrom
hw7-mergeSort
Open

mergeSort#28
Andrw-404 wants to merge 7 commits intomainfrom
hw7-mergeSort

Conversation

@Andrw-404
Copy link
Owner

No description provided.

free(list);
return NULL;
}
list->head->next = NULL;

Choose a reason for hiding this comment

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

А calloc и так это гарантирует, так что эта строка не сделает ничего

}
Position current = list->head;
while (current != NULL) {
printf("%s %s\n", current->name, current->phone);

This comment was marked as resolved.

List* createList(void);

// function for adding an element
void addContact(List* list, char* name, char* phone);

Choose a reason for hiding this comment

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

Лучше было бы const char* name, const char* phone. Как минимум, это позволит без боли и страха использовать строковые литералы в качестве аргументов

void printList(List* list);

// removes the entire list and frees memory
void removeList(List* list);

Choose a reason for hiding this comment

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

Лучше ** и сбрасывать указатель в NULL, чтобы у вызывающего не оставалось висячего указателя при удалении

void removeList(List* list);

// function for getting the name of the transmitted contact
char* getName(ListElement* element);

Choose a reason for hiding this comment

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

И тут лучше const char *

Comment on lines 10 to 17
// 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

Choose a reason for hiding this comment

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

Из этих трёх функций только одна реально тут нужна, остальные в .c-шнике только должны быть


#include <stdio.h>

void reader(const char* filename, List* list) {

Choose a reason for hiding this comment

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

Функуии именуются как глаголы в повелительной форме

Comment on lines 8 to 9
FILE* file = fopen(filename, "r");
if (file == NULL) {

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
char name[50];
char phone[20];

Choose a reason for hiding this comment

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

Массивы тоже надо инициализировать

#include <stdbool.h>
#include <string.h>

bool testSplit() {

Choose a reason for hiding this comment

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

Тестируем всегда только внешнее поведение, иначе тесты будут завязаны на особенности реализации модуля

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.

Всё ок — ещё один мемлик есть, но с очевидным фиксом, так что зачтена

List* first = NULL;
List* second = NULL;
split(list, &first, &second);

Choose a reason for hiding this comment

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

После этого list не нужен, его можно было бы тут удалить (и даже нужно, потому что иначе его так никто и не удалит)

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.

2 participants