15
This commit is contained in:
parent
ed44d7bd3c
commit
e6d94ab4d9
@ -39,11 +39,38 @@ void print_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) {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user