Seemingly fixed the logic

This commit is contained in:
Anton Dolozin 2025-10-28 20:26:49 +01:00
parent 70c14170fa
commit 50295427c8

View File

@ -61,18 +61,19 @@ struct car* clear_train(struct car* first, const char* target) {
return first;
}
struct car* prev= NULL;
struct car* temp = first;
struct car* next = first->next;
while (next->next)
{if(strcmp(next->value, target) == 0){
next->next = NULL;
temp->next = next->next;
free(next);
while (temp->next)
{
prev = temp;
temp = temp->next;
if(strcmp(temp->value, target) == 0){
prev->next = temp->next;
free(temp);
temp = prev->next;
}
else{
temp = next;
next = next->next;}
}