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