2020-10-26 14:07:14 +00:00
|
|
|
#include <stdio.h>
|
2020-11-02 13:48:59 +00:00
|
|
|
|
2020-10-26 14:07:14 +00:00
|
|
|
#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));
|
2020-11-02 12:13:53 +00:00
|
|
|
if(target == NULL){
|
2020-11-02 13:29:23 +00:00
|
|
|
return;
|
2020-11-02 12:13:53 +00:00
|
|
|
}
|
2020-10-26 13:38:06 +00:00
|
|
|
strcpy(newcar->value, target);
|
2020-11-02 11:12:53 +00:00
|
|
|
|
2020-10-26 13:38:06 +00:00
|
|
|
if(first == NULL){
|
2020-10-26 14:49:01 +00:00
|
|
|
return newcar;
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
2020-10-26 14:49:01 +00:00
|
|
|
struct car *this = first;
|
|
|
|
while(this->next != NULL){
|
|
|
|
this = this->next;
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
2020-10-26 14:49:01 +00:00
|
|
|
this->next = newcar;
|
2020-10-27 16:37:53 +00:00
|
|
|
return first;
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_train(struct car* first) {
|
2020-11-02 12:17:07 +00:00
|
|
|
for(struct car* this = first; this != NULL; this = this->next){
|
2020-11-02 12:16:13 +00:00
|
|
|
printf("%s\n", this->value);
|
|
|
|
}
|
|
|
|
/*struct car* this = first;
|
2020-11-02 10:42:12 +00:00
|
|
|
if(first == NULL){
|
2020-10-26 16:25:34 +00:00
|
|
|
exit(0);
|
2020-11-02 10:42:12 +00:00
|
|
|
}
|
|
|
|
else{
|
2020-11-02 10:37:31 +00:00
|
|
|
while(this != NULL){
|
2020-10-26 13:38:06 +00:00
|
|
|
printf("%s\n", this->value);
|
|
|
|
this = this->next;
|
|
|
|
}
|
2020-11-02 12:16:13 +00:00
|
|
|
}*/
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 17:59:58 +00:00
|
|
|
void cancel_train(struct car* first) {
|
2020-10-26 14:49:01 +00:00
|
|
|
if(first == NULL){
|
2020-11-02 13:46:04 +00:00
|
|
|
return;
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
2020-11-02 13:56:56 +00:00
|
|
|
else if(first->value != NULL){
|
2020-11-02 13:48:59 +00:00
|
|
|
struct car* help = first->next;
|
2020-11-02 13:46:04 +00:00
|
|
|
free(first);
|
2020-11-02 13:56:56 +00:00
|
|
|
//first->next = NULL;
|
2020-11-02 13:48:59 +00:00
|
|
|
cancel_train(help);
|
|
|
|
//first->next = NULL;
|
2020-10-26 16:49:41 +00:00
|
|
|
}
|
2020-11-02 13:46:04 +00:00
|
|
|
else if(first->next == NULL){
|
2020-11-02 13:27:52 +00:00
|
|
|
free(first);
|
2020-11-02 13:58:56 +00:00
|
|
|
cancel_train(first->next);
|
2020-11-01 18:41:36 +00:00
|
|
|
}
|
2020-10-27 17:43:29 +00:00
|
|
|
|
2020-10-26 13:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-27 17:18:34 +00:00
|
|
|
|
2020-10-26 13:38:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|