Skip to content

Comments

reckoning#29

Open
Andrw-404 wants to merge 22 commits intomainfrom
hw7-reckoning
Open

reckoning#29
Andrw-404 wants to merge 22 commits intomainfrom
hw7-reckoning

Conversation

@Andrw-404
Copy link
Owner

No description provided.

@@ -0,0 +1,155 @@
#include "list.h"

Choose a reason for hiding this comment

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

Как я понимаю, это в пуллреквесте про считалочку не нужно, у неё своя копия списка

if (list == NULL) {
return NULL;
}
list->head = calloc(1, sizeof(ListElement));

Choose a reason for hiding this comment

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

Циклическому списку вообще стражник не нужен, и с ним проще запутаться

return;
}
Position current = list->head->next;
while (current != NULL) {

Choose a reason for hiding this comment

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

В циклическом списке current никогда не будет NULL

Comment on lines 97 to 104
if (list->tail == list->head) {
list->head->next = element;
element->next = list->head;
}
else {
list->tail->next = element;
element->next = list->head;
}

Choose a reason for hiding this comment

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

Так это то же самое в then и else


Position current = list->head->next;

while (current != list->head && current != NULL) {

Choose a reason for hiding this comment

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

current != NULL всегда, если список правильный


while (current != list->head && current != NULL) {
Position next = current->next;
removeListElement(list, current);

Choose a reason for hiding this comment

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

Зачем линейную функцию тут вызывать, просто free(current).

Comment on lines 24 to 25
Position delete = current;
setNext(previous, getNext(current));

Choose a reason for hiding this comment

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

Тут мы пытаемся удалить элемент из списка извне самого списка, тем самым список не может уследить за своим инвариантом "голова и хвост указывают на неудалённые элементы" и всё падает. Тогда как у Вас есть removeListElement, который делает всё аккуратно. Тут вообще, кстати, неправда, потому что previous изначально указывает на хвост, current на элемент, следующий за гловой, и тут мы радостно выкидываем стражника из списка вовсе (а я говорил, что стражник тут — источник боли).

//function that changes the pointer to the next element
void setNext(ListElement* element, ListElement* next);

void removeListElement(List* list, Position position);

Choose a reason for hiding this comment

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

Комментарий нужен :)


typedef ListElement* Position;

//function to create a list

Choose a reason for hiding this comment

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

Надо пробел после //


int main(void) {
setlocale(LC_ALL, "RUS");
if (!runTests()) {

Choose a reason for hiding this comment

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

Это вроде как тесты на список, а тесты на саму задачу?

test: updated the tests for a new list and added a test for the main function
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.

Ага, стало лучше, зачтена

int m = 0;
int n = 0;
printf("\n������� ���������� ������: ");
scanf_s("%d", &n);

Choose a reason for hiding this comment

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

Не используйте scanf_s, его почти никто не поддерживает

return false;
}
return true;
} 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.

Как-то негусто :) Интересно было бы проверить шаг 1, иил некорректные значения

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