This commit is contained in:
Maryna Kravtsova 2020-11-03 20:43:01 +01:00
parent 5dc075a476
commit ee01429d40

View File

@ -64,17 +64,20 @@ struct car* clear_train(struct car* first, const char* target) {
while(first != NULL){
int x = strcmp(this->value, target);
if(x == 0){
struct car* prev = this;
struct car* node = this->next;
while(prev != NULL && node != NULL){
prev->next = node->next;
free(node);
prev = prev->next;
if(prev != NULL){
node = prev->next;
struct car* curr = first;
struct car* prev = NULL;
if(first == this){
first = this->next;
free(this);
return 0;
}
while(curr != this){
prev = curr;
curr = curr->next;
}
prev->next = curr->next;
free(this);
}
this = this->next;
}