Skip to content

Comments

Задача считалочка. Кальсина Яна Б43.#20

Open
yaprogrammer18-yanchi wants to merge 4 commits intomainfrom
counting_branch
Open

Задача считалочка. Кальсина Яна Б43.#20
yaprogrammer18-yanchi wants to merge 4 commits intomainfrom
counting_branch

Conversation

@yaprogrammer18-yanchi
Copy link
Owner

Добавила все файлы к задаче и cmake

Comment on lines +7 to +10
printf("Введите n и m через пробел\n");
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);

Choose a reason for hiding this comment

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

Вообще можно просто два scanf попросить, он их прочитает, если бы они были через пробел или через перенос строки (\n)

Comment on lines +50 to +60
int counter = 0;
while (1) {
if (counter == index - 1) {
ListNode* newNode = calloc(1, sizeof(ListNode));
newNode->value = value;
newNode->next = current->next;
current->next = newNode;
return true;
}
current = current->next;
counter++;

Choose a reason for hiding this comment

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

Тут можно написать for (int i = 0;;i++), получится то же самое

return new;
}

bool insert(List* list, int index, int value)

Choose a reason for hiding this comment

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

Вообще при добавлении можно не использовать список, в задании же всё равно заполняются последовательно

Comment on lines +77 to +80
ListNode* current = list->head;
while (current->next != elemToRemove) {
current = current->next;
}

Choose a reason for hiding this comment

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

Вообще чтобы вот так не искать хвост, его можно хранить в самом списке

Comment on lines +146 to +164
int findTheSafeIndex(List* list, int m)
{
ListNode* current = list->head;
ListNode* prev = NULL;
while (!oneElement(list)) {
for (int i = 0; i < m; i++) {
prev = current;
current = current->next;
}
if (current == list->head) {
list->head = current->next;
}

prev->next = current->next;
free(current);
current = prev->next;
}
return list->head->value;
}

Choose a reason for hiding this comment

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

То есть индексы вообще не нужны? Тут они нигде не упоминаются, вообще тогда можно сделать так, чтобы removeElement принимал в себя ListNode, и удалял его из списка

Comment on lines +51 to +67
/*
* функция вывода списка в консоль
* принимает только указаетль на список,
* ничего не возвращает
* печатает элементы списка через пробел
* в случае переданного пустого или несуществующего списка сообщает об этом
* пользователю
*/
void printList(List* list);

/*
* функция, возвращающая длину списка
* принимает на вход указатель на список
* проходится по всем элементам
* возвращает его длину
*/
int getLength(List* list);

Choose a reason for hiding this comment

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

Неиспользуемые функции

insert(list, i - 1, i);
}
printf("%d\n", findTheSafeIndex(list, m));
return 0;

Choose a reason for hiding this comment

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

Список (ну или то что от него осталось) не удаляется при выходе

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