Изменил(а) на 'cv4/a_train.c'
This commit is contained in:
parent
872b1fc5bd
commit
036b9fbe75
@ -1,18 +1,63 @@
|
|||||||
#include "a_train.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "a_train.h"
|
||||||
|
|
||||||
struct car* add_car(struct car* first,const char* target) {
|
struct car* add_car(struct car* first, const char* target){
|
||||||
return NULL;
|
if(!strcmp(target, "") && !first)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
struct car* temp = first;
|
||||||
|
|
||||||
|
while(temp->next != NULL)
|
||||||
|
temp = temp->next;
|
||||||
|
|
||||||
|
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) {
|
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) {
|
void cancel_train(struct car* first){
|
||||||
|
if(!first)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct car* temp = first;
|
||||||
|
struct car* next = temp->next;
|
||||||
|
|
||||||
|
while(next != NULL){
|
||||||
|
next = temp->next;
|
||||||
|
free(temp);
|
||||||
|
temp = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
first = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct car* clear_train(struct car* first, const char* target){
|
||||||
|
if(!first || !strcmp(target, ""))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
struct car* clear_train(struct car* first, const char* target) {
|
struct car* temp = first;
|
||||||
return NULL;
|
struct car* next = temp->next;
|
||||||
}
|
|
||||||
|
|
||||||
|
while(next != NULL){
|
||||||
|
next = temp->next;
|
||||||
|
if(!strcmp(temp->value, target))
|
||||||
|
free(temp);
|
||||||
|
temp = next;
|
||||||
|
if(!first)
|
||||||
|
first = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return first;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user