diff --git a/cv4/a_train.c b/cv4/a_train.c index 06f53de..8880447 100755 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -51,6 +51,13 @@ struct car* clear_train(struct car* first, const char* target) { return this; } } + if(this->next->next == NULL){ + if(strcmp(this->value, target) == 0){ + free(this); + this->next=NULL; + return this; + } + } while( this->next->next != NULL){ if(strcmp(this->value, target) == 0){ free(this->next); @@ -61,12 +68,5 @@ struct car* clear_train(struct car* first, const char* target) { this = this->next; } } - if(strcmp(this->value, target) ==0){ - free(this); - this->next = NULL; - return this; - } - else{ - return first; - } + return first; }