Initializacia

This commit is contained in:
Kozar 2024-10-20 13:06:03 +00:00
parent 91662d4ed8
commit c79715105c

View File

@ -33,37 +33,40 @@ void print_train(struct car* first) {
} }
void cancel_train(struct car* first) { void cancel_train(struct car* first) {
// struct car* current = first; struct car* current = first;
// while(first != NULL){ while(first != NULL){
// current = current->next; current = current->next;
// free(first); free(first);
// first = current; first = current;
// } }
} }
struct car* clear_train(struct car* first, const char* target) { struct car* clear_train(struct car* first, const char* target) {
if (first = NULL){ if (first == NULL) {
return NULL; return NULL;
} }
struct car* current = first, new_first = first;
if (first != NULL){ struct car* current = first;
if(strcmp(first->value, target) == 0){ struct car* previous = NULL;
new_first = new_first->next;
free(first); while (current != NULL && strcmp(current->value, target) == 0) {
first = new_first; struct car* temp = current;
} first = current->next;
current = first;
free(temp);
} }
while (first->next != NULL) { while (current != NULL) {
current = first->next;
if (strcmp(current->value, target) == 0) { if (strcmp(current->value, target) == 0) {
first->next = current->next; previous->next = current->next;
free(current); free(current);
current = previous->next;
} else { } else {
first = current; previous = current;
current = current->next;
} }
} }
return new_first;
}
return first;
}