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

View File

@ -58,50 +58,28 @@ struct car* clear_train(struct car* first, const char* target) {
free(first); free(first);
return 0; return 0;
} }
}
//struct car* this = first;
/*if(first->next->next == NULL){
int x = strcmp(this->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{ else{
secondlast->next = NULL;
}
free(this);
}
} */
else{
struct car* this = first;
while(this->next!= NULL){
int x = strcmp(this->value, target);
if(x == 0){
struct car* curr = first;
struct car* prev = NULL;
if(first == this){
first = this->next;
free(this);
//first->next = NULL;
return first; return first;
} }
while(curr != this){ }
prev = curr; struct car* prev = first;
curr = curr->next; while(prev->next->next != NULL){
int x = strcmp(prev->next->value, target);
if(x == 0){
struct car* third = prev->next->next;
free(prev->next);
prev->next = third;
return first;
}
prev = prev->next;
}
int x = strcmp(prev->next->value, target);
if(x == 0){
free(prev->next);
prev->next = NULL;
return first;
} }
prev->next = curr->next;
this->next = NULL;
free(this);
}
this = this->next;
}
}
return first; return first;
} }