From d52508b1000a16c35f10ccfcceb1caa2660a64f2 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Thu, 5 Nov 2020 15:41:59 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index af518c1..6dd4842 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -66,21 +66,34 @@ struct car* clear_train(struct car* first, const char* target) { while(prev->next->next != NULL){ int x = strcmp(first->value, target); if(x == 0){ - first = first->next; - free(prev); - return first; + prev = first->next; + free(first); + return prev; } x = strcmp(prev->next->value, target); - if(x == 0){ - if(first->next->next == NULL) { + // if(x == 0){ + /* if(first->next->next == NULL) { //struct car* tmp = prev->next; free(prev->next); prev->next = NULL; - } - } + }*/ + //} prev = prev->next; } + if(prev->next->next == NULL) { + int x = strcmp(first->value, target); + if(x == 0){ + prev = first->next; + free(first); + return prev; + + } + free(prev->next); + prev->next = NULL; + } + + return first; }