diff --git a/cv5/a_train.c b/cv5/a_train.c index 632e564..643e8d4 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -45,7 +45,7 @@ void print_train(struct car* first) { void cancel_train(struct car* first) { if(first == NULL){ - return; + return 0; } if(first->next != NULL){ cancel_train(first->next); @@ -65,14 +65,27 @@ struct car* clear_train(struct car* first, const char* target) { if(first == NULL){ return 0; } - struct car* this = first; - while(this != NULL){ - if(this->value == target){ - return NULL; - } - this = this->next; - + int x; + if(first->next == NULL){ + x = strcmp(first->value; target); + if(x == 0){ + free(first); + return 0; + } } - return first; + else{ + struct car* prev = first; + while(prev->next->next != NULL){ + x = strcmp(prev->next->value, target); + if(x == 0){ + struct car* third = prev->next->next; + free(prev->next); + break; + } + prev = prev->next; + + } + } + return first; }