This commit is contained in:
Maryna Kravtsova 2020-11-04 22:29:07 +01:00
parent eaab488d65
commit 4aeb52f77e

View File

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