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;
}
}
struct car* prev = first;
while(prev->next->next != NULL){
int x = strcmp(prev->next->value, target);
struct car* this = first;
while(this->next->next != NULL){
int x = strcmp(this->next->value, target);
if(x == 0){
struct car* third = prev->next->next;
free(prev->next);
prev->next = third;
return prev;
struct car* curr = first;
struct car* prev = NULL;
if(first == this){
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){
free(prev->next);
prev->next = NULL;
free(this->next);
this->next = NULL;
return first;
}
return first;