diff --git a/cv5/a_train.c b/cv5/a_train.c index 87a7a4c..8e42f31 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -62,24 +62,25 @@ struct car* clear_train(struct car* first, const char* target) { return first; } } - struct car* temp = first; struct car* prev = first; - while(temp != NULL){ - int x = strcmp(temp->value, target); - if(x != 0){ - prev = temp; - temp = temp->next; + while(prev->next->next != NULL){ + int x = strcmp(prev->next->value, target); + if(x == 0){ + struct car* third = prev->next->next; + free(prev->next); + prev->next = third; + return third; } - else{ - break; - } - - } - if(temp == NULL){ - return 0; - } - prev->next = temp->next; - free(temp); - return first; + prev = prev->next; + } + + + int x = strcmp(prev->next->value, target); + if(x == 0){ + free(prev->next); + prev->next = NULL; + return first; + } + return first; }