This commit is contained in:
Oleksandr Vyshniakov 2025-11-25 21:22:09 +01:00
parent 5a85ff5800
commit ea7b709255

View File

@ -13,18 +13,18 @@ struct car* add_car (struct car* first, const char* target) {
strncpy(novyj_vagon->value, target, SIZE - 1);
novyj_vagon->value[SIZE - 1] = '\0';
novyj_vagon->next = NULL;
novyj_vagon->next = NULL; //Устанавливаем, что у нового вагона нет следующего
if (first == NULL) {
return novyj_vagon;
}
struct car* actual = first;
struct car* actual = first;//указатель для прохода по списку.
while (actual->next != NULL) {
actual = actual->next;
}
actual->next = novyj_vagon;
return first;
return first; //Возвращаем неизменённый первый элемент
}
void print_train (struct car* first) {
@ -51,7 +51,7 @@ void cancel_train (struct car* first) {
struct car* current = first;
while (current !=NULL) {
struct car* next_one = current->next;// запоминаем следующий вагон
memset(current->value, 0, SIZE);
memset(current->value, 0, SIZE); //Очищаем содержимое value
free(current);
current = next_one;; // переходим к следующему вагону
}