This commit is contained in:
Maryna Kravtsova 2020-11-02 16:59:59 +01:00
parent 8e6497b6e8
commit 7bd7f9c076

View File

@ -45,7 +45,7 @@ void print_train(struct car* first) {
void cancel_train(struct car* first) { void cancel_train(struct car* first) {
if(first == NULL){ if(first == NULL){
return; return 0;
} }
if(first->next != NULL){ if(first->next != NULL){
cancel_train(first->next); cancel_train(first->next);
@ -65,14 +65,27 @@ struct car* clear_train(struct car* first, const char* target) {
if(first == NULL){ if(first == NULL){
return 0; return 0;
} }
struct car* this = first; int x;
while(this != NULL){ if(first->next == NULL){
if(this->value == target){ x = strcmp(first->value; target);
return NULL; if(x == 0){
free(first);
return 0;
} }
this = this->next; }
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; return first;
} }