2020-10-26 14:07:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-10-26 13:38:06 +00:00
|
|
|
#include "a_train.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
struct car *this = first;
|
|
|
|
while(this->next != NULL){
|
|
|
|
this = this->next;
|
|
|
|
}
|
|
|
|
this->next = newcar;
|
|
|
|
}
|
|
|
|
return first;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_train(struct car* first) {
|
|
|
|
struct car* this = first;
|
|
|
|
if(first == NULL){
|
|
|
|
printf("List is empty.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
while(this != NULL){
|
|
|
|
printf("%s\n", this->value);
|
|
|
|
this = this->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cancel_train(struct car* first) {
|
|
|
|
if(first != NULL){
|
|
|
|
cancel_train(first->next);
|
|
|
|
free(first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct car* clear_train(struct car* first, const char* target) {
|
|
|
|
struct car* this = first;
|
|
|
|
while(this != NULL){
|
|
|
|
if(this->value == target){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
this = this->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|