diff --git a/cv5/a_train.c b/cv5/a_train.c index 4a272b5..84d9a65 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -63,23 +63,26 @@ struct car* clear_train(struct car* first, const char* target) { } } struct car* this = first; - while(this->next->next != NULL){ - int x = strcmp(this->next->value, target); + while(this->next != NULL){ + int x = strcmp(this->value, target); if(x == 0){ - struct car* prev = first; - struct car* node = first->next; + struct car* tmp = first; + struct car* prev = NULL; if(first == this){ first = this->next; free(this); return first; } - while(prev != NULL && node != NULL){ - prev->next = node->next; - free(node); - prev = prev->next; - if(prev != NULL) - node = prev->next; - } + else{ + while(tmp->next != NULL){ + prev = tmp; + tmp = tmp->next; + } + free(prev->next); + prev->next = NULL; + + } + } this = this->next;