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; } -