From 120b613700ca3d306ed93aef1973304d4dc8e060 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Mon, 26 Oct 2020 15:49:01 +0100 Subject: [PATCH] train --- cv5/a_train.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 38c951b..dbc539e 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -8,15 +8,13 @@ struct car* add_car(struct car* first,const char* target) { struct car* newcar = calloc(1, sizeof(struct car)); strcpy(newcar->value, target); if(first == NULL){ - first = newcar; + return newcar; } - else{ - struct car *this = first; - while(this->next != NULL){ - this = this->next; - } - this->next = newcar; + struct car *this = first; + while(this->next != NULL){ + this = this->next; } + this->next = newcar; return first; } @@ -24,7 +22,6 @@ struct car* add_car(struct car* first,const char* target) { void print_train(struct car* first) { struct car* this = first; if(first == NULL){ - printf("List is empty."); return; } else{ @@ -37,10 +34,11 @@ void print_train(struct car* first) { void cancel_train(struct car* first) { - if(first != NULL){ - cancel_train(first->next); - free(first); + if(first == NULL){ + return; } + cancel_train(first->next); + free(first); }