#include #include #include #include "a_train.h" <<<<<<< HEAD struct car* add_car(struct car* first, const char* target){ if(!strcmp(target, "")) return NULL; if(!first){ ======= struct car* add_car(struct car* first, const char* target){ if(!strcmp(target, "")) return NULL; if(!first || !strcmp(first->value, "")){ >>>>>>> 2033291145353cf5a29605aaa70523464ca047fa first = (struct car*)calloc(1, sizeof(struct car)); strcpy(first->value, target); first->next = NULL; return first; } <<<<<<< HEAD struct car* temp = first; while(temp->next != NULL) temp = temp->next; ======= struct car* temp = first; while(temp->next != NULL) temp = temp->next; >>>>>>> 2033291145353cf5a29605aaa70523464ca047fa temp->next = (struct car*)calloc(1, sizeof(struct car)); strcpy(temp->next->value, target); temp->next->next = NULL; return first; } void print_train(struct car* first){ struct car* temp = first; while(temp != NULL){ printf("%s\n", temp->value); temp = temp->next; } } void cancel_train(struct car* first){ if(!first) return; <<<<<<< HEAD struct car* temp = first; struct car* next = temp->next; while(next != NULL){ next = temp->next; free(temp); temp = next; } ======= struct car* temp = first; struct car* next = temp->next; while(next != NULL){ next = temp->next; free(temp); temp = next; } >>>>>>> 2033291145353cf5a29605aaa70523464ca047fa first = NULL; } struct car* clear_train(struct car* first, const char* target){ if(!first || !strcmp(target, "")) return NULL; struct car* temp = first; struct car* next = temp->next; while(temp != NULL){ next = temp->next; <<<<<<< HEAD if(!strcmp(temp->value, target)) free(temp); ======= if(!strcmp(temp->value, target)) { if(temp == first) { free(first); first = NULL; } else free(temp); } >>>>>>> 2033291145353cf5a29605aaa70523464ca047fa temp = next; if(!first) first = temp; } return first; }