Conversation
| @@ -0,0 +1,161 @@ | |||
| #include "list.h" | |||
There was a problem hiding this comment.
Кажется, это тут не нужно, у sortedList есть своя копия списка
|
|
||
| #include <stdbool.h> | ||
|
|
||
| //test for a function that adds an item to a sorted list |
| #include <stdio.h> | ||
|
|
||
| int main(void) { | ||
| setlocale(LC_ALL, "Rus"); |
There was a problem hiding this comment.
Не используйте табуляции для отступов, и тем более не мешайте разные стили отступов в одном проекте
| if (list == NULL) { | ||
| return NULL; | ||
| } | ||
| list->head = calloc(1, sizeof(ListElement)); |
There was a problem hiding this comment.
Для сортированного списка стражник не нужен, потому что у него нет вставки по позиции
|
|
||
| Value getValue(List* list, Position position) { | ||
| if (position == NULL) { | ||
| return (Value)0; |
There was a problem hiding this comment.
По-хорошему тут надо тоже error reporting, потому что 0 неотличим от валидного значения
| return; | ||
| } | ||
| ListElement* element = malloc(sizeof(ListElement)); | ||
| element->value = value; |
There was a problem hiding this comment.
Надо проверять успешность malloc
| free(current); | ||
| current = next; | ||
| } | ||
| free(first(list)); |
There was a problem hiding this comment.
| free(first(list)); | |
| free(list->head); |
Внутри модуля такие условности несколько избыточны
| } | ||
|
|
||
| if (current->next == NULL) { | ||
| printf("\n!!!Такой элемент не найден\n"); |
There was a problem hiding this comment.
Не общайтесь с пользователем вне main
| List* list = createList(); | ||
| addLast(list, 10); | ||
| if (isEmpty(list) || getValue(list, getPositionByNumber(list, 1)) != 10) { | ||
| return false; |
| addElements(-19, listForAddTest); | ||
| addElements(4, listForAddTest); | ||
| if (isEmpty(listForAddTest)) { | ||
| return false; |
There was a problem hiding this comment.
И тут и в аналогичных ситуациях ниже. Список может быть пуст, когда у него есть и сама структура "Список" и стражник в голове, их ведь тоже удалить надо.
No description provided.