This commit is contained in:
Maryna Kravtsova 2020-11-04 11:08:03 +01:00
parent f5088bf6e8
commit 2a249097a5

View File

@ -57,51 +57,29 @@ struct car* clear_train(struct car* first, const char* target) {
if(result == 0){ if(result == 0){
free(first); free(first);
return 0; return 0;
} }
else{
return first;
}
} }
//struct car* this = first; struct car* prev = first;
/*if(first->next->next == NULL){ while(prev->next->next != NULL){
int x = strcmp(this->next->value, target); int x = strcmp(prev->next->value, target);
if(x == 0){
struct car* secondlast = first;
while(this->next != NULL){
secondlast = this;
this = this->next;
}
if(this == first){
first = NULL;
}
else{
secondlast->next = NULL;
}
free(this);
}
} */
else{
struct car* this = first;
while(this->next!= NULL){
int x = strcmp(this->value, target);
if(x == 0){ if(x == 0){
struct car* curr = first; struct car* third = prev->next->next;
struct car* prev = NULL; free(prev->next);
if(first == this){ prev->next = third;
first = this->next; return first;
free(this);
//first->next = NULL;
return first;
}
while(curr != this){
prev = curr;
curr = curr->next;
}
prev->next = curr->next;
this->next = NULL;
free(this);
} }
this = this->next; prev = prev->next;
} }
} int x = strcmp(prev->next->value, target);
return first; if(x == 0){
free(prev->next);
prev->next = NULL;
return first;
}
return first;
} }