From 2b24ea04493ef80abcdcbfd920295e9e2d1d393a Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Thu, 5 Nov 2020 16:54:29 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 1ebbae1..8e85900 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -51,18 +51,22 @@ struct car* clear_train(struct car* first, const char* target) { if(first == NULL){ return 0; } - + + if(first->next == NULL){ + int result = strcmp(first->value, target); + if(result == 0){ + free(first); + return 0; + } + else{ + return first; + } + } + struct car* prev = first; while(prev->next != NULL){ int x = strcmp(first->value, target); if(x == 0){ - if(first->next == NULL){ - free(first); - return NULL; - } - else{ - return first; - } prev = first->next; free(first); return prev;