diff --git a/cv5/a_train.c b/cv5/a_train.c index 265da50..d9200e0 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -63,31 +63,19 @@ struct car* clear_train(struct car* first, const char* target) { } } struct car* this = first; - while(this->next != NULL){ - int x = strcmp(this->value, target); + while(this->next->next != NULL){ + int x = strcmp(this->next->value, target); if(x == 0){ - struct car* tmp = first; - struct car* prev = first; + struct car* third = this->next->next; if(first == this){ first = this->next; free(this); return first; } - if(first->next == this){ - while(tmp->next != NULL){ - prev = tmp; - tmp = tmp->next; - } - if(tmp == first){ - first = NULL; - } - else{ - prev->next = NULL; - } - free(tmp); + else { + free(this->next); + this->next = third; } - - } this = this->next; }