train
This commit is contained in:
parent
4759677c57
commit
120b613700
@ -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){
|
||||||
cancel_train(first->next);
|
return;
|
||||||
free(first);
|
|
||||||
}
|
}
|
||||||
|
cancel_train(first->next);
|
||||||
|
free(first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user