From 6c79f0d25092133328c30cd8d77ab0a3527b322d Mon Sep 17 00:00:00 2001 From: Kozar Date: Sun, 20 Oct 2024 13:00:06 +0000 Subject: [PATCH] Initializacia --- cv4/a_train.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cv4/a_train.c b/cv4/a_train.c index 021890c..b175afa 100644 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -43,27 +43,27 @@ void cancel_train(struct car* first) { struct car* clear_train(struct car* first, const char* target) { - // if (first = NULL){ - // return NULL; - // } - // struct car* current = first, new_first = first; - // if (first != NULL){ - // if(strcmp(first->destination, target) == 0){ - // new_first = new_first->next; - // free(first); - // first = new_first; - // } - // } + if (first = NULL){ + return NULL; + } + struct car* current = first, new_first = first; + if (first != NULL){ + if(strcmp(first->destination, target) == 0){ + new_first = new_first->next; + free(first); + first = new_first; + } + } - // while (first->next != NULL) { - // current = first->next; - // if (strcmp(current->destination, target) == 0) { - // first->next = current->next; - // free(current); - // } else { - // first = current; - // } - // } - // return new_first; + while (first->next != NULL) { + current = first->next; + if (strcmp(current->destination, target) == 0) { + first->next = current->next; + free(current); + } else { + first = current; + } + } + return new_first; }