From ff410acb179f503b7d38cd73a7b4a89432ca5f91 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Thu, 5 Nov 2020 10:35:17 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 265da50..d9200e0 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -63,31 +63,19 @@ struct car* clear_train(struct car* first, const char* target) { } } struct car* this = first; - while(this->next != NULL){ - int x = strcmp(this->value, target); + while(this->next->next != NULL){ + int x = strcmp(this->next->value, target); if(x == 0){ - struct car* tmp = first; - struct car* prev = first; + struct car* third = this->next->next; if(first == this){ first = this->next; free(this); return first; } - if(first->next == this){ - while(tmp->next != NULL){ - prev = tmp; - tmp = tmp->next; - } - if(tmp == first){ - first = NULL; - } - else{ - prev->next = NULL; - } - free(tmp); + else { + free(this->next); + this->next = third; } - - } this = this->next; }