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