This commit is contained in:
Maryna Kravtsova 2020-11-05 10:35:17 +01:00
parent c8beff4de8
commit ff410acb17

View File

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