This commit is contained in:
Maryna Kravtsova 2020-11-05 15:22:56 +01:00
parent 8fd5decb45
commit a957a8266f

View File

@ -62,24 +62,25 @@ struct car* clear_train(struct car* first, const char* target) {
return first; return first;
} }
} }
struct car* this = first; struct car* prev = first;
while(this->next != NULL){ while(prev->next->next != NULL){
int x = strcmp(this->value, target); int x = strcmp(prev->value, target);
if(x == 0){ if(x == 0){
struct car* third = this->next->next; first = NULL;
if(first == this){ first = prev->next;
first = this->next; free(prev);
free(this);
return first;
}
else {
free(this->next);
this->next = third;
}
} }
this = this->next; x = strcmp(prev->next->value, target);
} if(x == 0){
if(first->next->next == NULL) {
//struct car* tmp = prev->next;
free(prev->next);
prev->next = NULL;
}
}
prev = prev->next;
}
return first; return first;
} }