diff --git a/cv5/a_train.c b/cv5/a_train.c index 027fbcd..0dca5c8 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -66,20 +66,20 @@ struct car* clear_train(struct car* first, const char* target) { while(this->next != NULL){ int x = strcmp(this->value, target); if(x == 0){ - struct car* curr = first; - struct car* prev = NULL; + struct car* prev = first; + struct car* node = first->next; if(first == this){ first = this->next; free(this); return first; } - while(curr != this){ - prev = curr; - curr = curr->next; + while(prev != NULL && node != NULL){ + prev->next = node->next; + free(node); + prev = prev->next; + if(prev != NULL) + node = prev->next; } - curr->next = prev->next; - this->next = NULL; - free(this); } this = this->next;