From 33a7361c9d1ce1757a3a425baca62d69e92f5405 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Wed, 4 Nov 2020 22:17:28 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 0bef6ec..87a7a4c 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -62,25 +62,24 @@ struct car* clear_train(struct car* first, const char* target) { return first; } } + struct car* temp = first; struct car* prev = first; - while(prev->next!= NULL){ - int x = strcmp(prev->next->value, target); - if(x == 0){ - struct car* third = prev->next->next; - free(prev->next); - prev->next = third; - prev->next->next = NULL; - return first; - } - prev = prev->next; + while(temp != NULL){ + int x = strcmp(temp->value, target); + if(x != 0){ + prev = temp; + temp = temp->next; } - int x = strcmp(prev->next->value, target); - if(x == 0){ - free(prev->next); - prev->next = NULL; - return first; - + else{ + break; } + + } + if(temp == NULL){ + return 0; + } + prev->next = temp->next; + free(temp); return first; - + }