From a12780d4aa75b3b94f2c10f4c620fe86a8f5682b Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Tue, 3 Nov 2020 21:00:24 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 0ff8ff7..b9b28c0 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -59,8 +59,25 @@ struct car* clear_train(struct car* first, const char* target) { return 0; } } + struct car* this = first; + if(first->next->next == NULL){ + int x = strcmp(this->next->value, target); + if(x == 0){ + struct car* secondlast = first; + while(this->next != NULL){ + secondlast = this; + this = this->next; + } + if(this == first){ + first = NULL; + } + else{ + secondlast->next = NULL; + } + free(this); + } + } else{ - struct car* this = first; while(this != NULL){ int x = strcmp(this->value, target); if(x == 0){ @@ -84,4 +101,3 @@ struct car* clear_train(struct car* first, const char* target) { } return first; } -