From e974217b7d39da9221fd0d91d34eac3fd985448f Mon Sep 17 00:00:00 2001 From: vj586da Date: Thu, 4 Nov 2021 20:08:37 +0100 Subject: [PATCH] first commit --- cv4/a_train.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 cv4/a_train.c diff --git a/cv4/a_train.c b/cv4/a_train.c new file mode 100755 index 0000000..fdc6d4b --- /dev/null +++ b/cv4/a_train.c @@ -0,0 +1,50 @@ +#include "a_train.h" +#include + +struct car* add_car(struct car* first,const char* target) { + strucr car* new_car = (struct car*)calloc(1,sizeof(struct car)); + strcpy(new_car->value, target); + new_car->next = NULL; + if (first == NULL){ + first = new_car; + } + else { + struct car* temp=first; + while(temp->next != NULL){ + temp = temp->next; + } + temp->next = new_car; + } + return first; +} + +void print_train(struct car* first) { + struct car* this = first; + while(this != NULL){ + printf("%s",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->next->next != NULL){ + if(strcmp(this->next->value, target, SIZE) == 0){ + this->next == this->next->next; + free(this); + } + this = this->next; + } + return NULL; +} +