This commit is contained in:
Valér Jakubčo 2021-11-05 08:38:35 +01:00
parent 43dd34d895
commit 1b5c0f5406

View File

@ -51,7 +51,7 @@ struct car* clear_train(struct car* first, const char* target) {
return this; return this;
} }
} }
if(this->next->next == NULL){ /*if(this->next->next == NULL){
if(strcmp(this->value, target) == 0){ if(strcmp(this->value, target) == 0){
struct car* tmp = this->next; struct car* tmp = this->next;
free(this); free(this);
@ -61,7 +61,7 @@ struct car* clear_train(struct car* first, const char* target) {
this->next=NULL; this->next=NULL;
return this; return this;
} }
} }*/
while( this->next->next != NULL){ while( this->next->next != NULL){
if(strcmp(this->next->value, target) == 0){ if(strcmp(this->next->value, target) == 0){
struct car* third = this->next->next; struct car* third = this->next->next;
@ -73,13 +73,13 @@ struct car* clear_train(struct car* first, const char* target) {
this = this->next; this = this->next;
} }
} }
if(strcmp(this->next->value, target) == 0){ if(strcmp(this->value, target) == 0){
struct car* tmp = this->next;
free(this);
return tmp;
}else if(strcmp(this->next->value, target) == 0){
free(this->next); free(this->next);
this->next=this->next->next; this->next=NULL;
return this;
}else if(strcmp(this->next->next->value, target) == 0){
free(this->next->next);
this->next->next=NULL;
return this; return this;
} }
return first; return first;