diff --git a/cv4/a_train.c b/cv4/a_train.c index f202840..2b9d0e5 100755 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -51,7 +51,7 @@ struct car* clear_train(struct car* first, const char* target) { return this; } } - if(this->next->next == NULL){ + /*if(this->next->next == NULL){ if(strcmp(this->value, target) == 0){ struct car* tmp = this->next; free(this); @@ -61,7 +61,7 @@ struct car* clear_train(struct car* first, const char* target) { this->next=NULL; return this; } - } + }*/ while( this->next->next != NULL){ if(strcmp(this->next->value, target) == 0){ struct car* third = this->next->next; @@ -73,13 +73,13 @@ struct car* clear_train(struct car* first, const char* target) { 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); - this->next=this->next->next; - return this; - }else if(strcmp(this->next->next->value, target) == 0){ - free(this->next->next); - this->next->next=NULL; + this->next=NULL; return this; } return first;