This commit is contained in:
Džubara 2024-10-24 19:26:06 +02:00
parent ed44d7bd3c
commit e6d94ab4d9

View File

@ -39,11 +39,38 @@ void print_train(struct car* first) {
} }
void cancel_train(struct car* first) { void cancel_train(struct car* first) {
struct car* temp;
while (first != NULL) {
temp = first;
first = first->next;
free(temp);
}
printf("Vsetky vozne boli zrusene.\n");
} }
struct car* clear_train(struct car* first, const char* target) { struct car* clear_train(struct car* first, const char* target) {
return NULL; struct car* current = first;
struct car* previous = NULL;
while (current != NULL) {
// Porovnanie hodnoty cielovej stanice
if (strcmp(current->value, target) == 0) {
// Ak sa cielova stanica zhoduje, odstráni vozeň
if (previous == NULL) {
// Ak je to prvý vozeň
first = current->next;
} else {
previous->next = current->next;
}
struct car* temp = current;
current = current->next;
free(temp);
} else {
// Ak sa nezhoduje, prejde na nasledujúci vozeň
previous = current;
current = current->next;
}
} }
return first;
}