From 6219ef427888ab50aa96f7b6fcf6aedc715ccd8f Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Wed, 4 Nov 2020 23:10:29 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 4a272b5..84d9a65 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -63,23 +63,26 @@ struct car* clear_train(struct car* first, const char* target) { } } struct car* this = first; - while(this->next->next != NULL){ - int x = strcmp(this->next->value, target); + while(this->next != NULL){ + int x = strcmp(this->value, target); if(x == 0){ - struct car* prev = first; - struct car* node = first->next; + struct car* tmp = first; + struct car* prev = NULL; if(first == this){ first = this->next; free(this); return first; } - while(prev != NULL && node != NULL){ - prev->next = node->next; - free(node); - prev = prev->next; - if(prev != NULL) - node = prev->next; - } + else{ + while(tmp->next != NULL){ + prev = tmp; + tmp = tmp->next; + } + free(prev->next); + prev->next = NULL; + + } + } this = this->next;