Conversation
| @@ -0,0 +1,155 @@ | |||
| #include "list.h" | |||
There was a problem hiding this comment.
Как я понимаю, это в пуллреквесте про считалочку не нужно, у неё своя копия списка
hw7/reckoning/list.c
Outdated
| if (list == NULL) { | ||
| return NULL; | ||
| } | ||
| list->head = calloc(1, sizeof(ListElement)); |
There was a problem hiding this comment.
Циклическому списку вообще стражник не нужен, и с ним проще запутаться
hw7/reckoning/list.c
Outdated
| return; | ||
| } | ||
| Position current = list->head->next; | ||
| while (current != NULL) { |
There was a problem hiding this comment.
В циклическом списке current никогда не будет NULL
hw7/reckoning/list.c
Outdated
| if (list->tail == list->head) { | ||
| list->head->next = element; | ||
| element->next = list->head; | ||
| } | ||
| else { | ||
| list->tail->next = element; | ||
| element->next = list->head; | ||
| } |
There was a problem hiding this comment.
Так это то же самое в then и else
hw7/reckoning/list.c
Outdated
|
|
||
| Position current = list->head->next; | ||
|
|
||
| while (current != list->head && current != NULL) { |
There was a problem hiding this comment.
current != NULL всегда, если список правильный
hw7/reckoning/list.c
Outdated
|
|
||
| while (current != list->head && current != NULL) { | ||
| Position next = current->next; | ||
| removeListElement(list, current); |
There was a problem hiding this comment.
Зачем линейную функцию тут вызывать, просто free(current).
hw7/reckoning/reckoning.c
Outdated
| Position delete = current; | ||
| setNext(previous, getNext(current)); |
There was a problem hiding this comment.
Тут мы пытаемся удалить элемент из списка извне самого списка, тем самым список не может уследить за своим инвариантом "голова и хвост указывают на неудалённые элементы" и всё падает. Тогда как у Вас есть removeListElement, который делает всё аккуратно. Тут вообще, кстати, неправда, потому что previous изначально указывает на хвост, current на элемент, следующий за гловой, и тут мы радостно выкидываем стражника из списка вовсе (а я говорил, что стражник тут — источник боли).
hw7/reckoning/list.h
Outdated
| //function that changes the pointer to the next element | ||
| void setNext(ListElement* element, ListElement* next); | ||
|
|
||
| void removeListElement(List* list, Position position); |
hw7/reckoning/list.h
Outdated
|
|
||
| typedef ListElement* Position; | ||
|
|
||
| //function to create a list |
hw7/reckoning/main.c
Outdated
|
|
||
| int main(void) { | ||
| setlocale(LC_ALL, "RUS"); | ||
| if (!runTests()) { |
There was a problem hiding this comment.
Это вроде как тесты на список, а тесты на саму задачу?
test: updated the tests for a new list and added a test for the main function
| int m = 0; | ||
| int n = 0; | ||
| printf("\n������� ���������� ������: "); | ||
| scanf_s("%d", &n); |
There was a problem hiding this comment.
Не используйте scanf_s, его почти никто не поддерживает
| return false; | ||
| } | ||
| return true; | ||
| } No newline at end of file |
There was a problem hiding this comment.
Как-то негусто :) Интересно было бы проверить шаг 1, иил некорректные значения
No description provided.