This commit is contained in:
Maryna Kravtsova 2020-10-26 15:49:01 +01:00
parent 4759677c57
commit 120b613700

View File

@ -8,15 +8,13 @@ struct car* add_car(struct car* first,const char* target) {
struct car* newcar = calloc(1, sizeof(struct car)); struct car* newcar = calloc(1, sizeof(struct car));
strcpy(newcar->value, target); strcpy(newcar->value, target);
if(first == NULL){ if(first == NULL){
first = newcar; return newcar;
} }
else{
struct car *this = first; struct car *this = first;
while(this->next != NULL){ while(this->next != NULL){
this = this->next; this = this->next;
} }
this->next = newcar; this->next = newcar;
}
return first; return first;
} }
@ -24,7 +22,6 @@ struct car* add_car(struct car* first,const char* target) {
void print_train(struct car* first) { void print_train(struct car* first) {
struct car* this = first; struct car* this = first;
if(first == NULL){ if(first == NULL){
printf("List is empty.");
return; return;
} }
else{ else{
@ -37,10 +34,11 @@ 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;
}
cancel_train(first->next); cancel_train(first->next);
free(first); free(first);
}
} }