diff --git a/cv5/a_train.c b/cv5/a_train.c index 5865147..ae2b161 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -36,9 +36,14 @@ void print_train(struct car* first) { void cancel_train(struct car* first) { if(first!=NULL){ - first=first->next; - free(first->next); - cancel_train(first); + struct car* temp= first; + struct car* next; + while(temp!=NULL){ + next=temp->next; + free(temp); + temp=next; + } + first=NULL; } }