From 96151e5e3bf590e263899aab03045242bea6d476 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Tue, 27 Oct 2020 17:37:53 +0100 Subject: [PATCH] train2 --- cv5/a_train.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index fe3ee11..5f0b59e 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -15,8 +15,7 @@ struct car* add_car(struct car* first,const char* target) { this = this->next; } this->next = newcar; - return first; - + return first; } void print_train(struct car* first) { @@ -32,18 +31,15 @@ void print_train(struct car* first) { } } - void cancel_train(struct car* first) { + struct car *this = first->next; if(first == NULL){ exit(0); } - if(first->next == NULL){ - struct car *this = first; - first = first->next; - free(this); - exit(0); + if(first->value == NULL){ + free(first); } - cancel_train(first->next); + cancel_train(this->next); free(first); }