From 50295427c8d543233996bcb33e78931921d8aa20 Mon Sep 17 00:00:00 2001 From: Anton Dolozin Date: Tue, 28 Oct 2025 20:26:49 +0100 Subject: [PATCH] Seemingly fixed the logic --- du4/a_train.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/du4/a_train.c b/du4/a_train.c index 72f40e0..1321d8f 100644 --- a/du4/a_train.c +++ b/du4/a_train.c @@ -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;} }