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