This commit is contained in:
Maryna Kravtsova 2020-11-04 23:01:42 +01:00
parent 466f69ab17
commit 98ba737b3f

View File

@ -66,20 +66,20 @@ struct car* clear_train(struct car* first, const char* target) {
while(this->next != NULL){ while(this->next != NULL){
int x = strcmp(this->value, target); int x = strcmp(this->value, target);
if(x == 0){ if(x == 0){
struct car* curr = first; struct car* prev = first;
struct car* prev = NULL; struct car* node = first->next;
if(first == this){ if(first == this){
first = this->next; first = this->next;
free(this); free(this);
return first; return first;
} }
while(curr != this){ while(prev != NULL && node != NULL){
prev = curr; prev->next = node->next;
curr = curr->next; free(node);
prev = prev->next;
if(prev != NULL)
node = prev->next;
} }
curr->next = prev->next;
this->next = NULL;
free(this);
} }
this = this->next; this = this->next;