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));
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);
}