From 090dc461f36d27162d2f7fb8c64ee7735876311b Mon Sep 17 00:00:00 2001 From: Ivan Leichenko Date: Fri, 18 Oct 2024 00:01:23 +0200 Subject: [PATCH] clear train hell cv4 --- cv4/a_train.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cv4/a_train.c b/cv4/a_train.c index 4e252b2..dd0f56f 100644 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -76,6 +76,8 @@ struct car* clear_train(struct car* first, const char* target) } } struct car* prev = first; + struct car* bef_prev = first; + if(prev->next->next == NULL) { @@ -98,17 +100,44 @@ struct car* clear_train(struct car* first, const char* target) } } + while (prev->next->next != NULL) { - if(strcmp(prev->value, target)) + if(!strcmp(prev->value, target)) { struct car* third = prev->next->next; free(prev->next); prev->next = third; return first; } + if(prev->next->next != NULL) + { + bef_prev = prev; + } prev = prev->next; } + + if(prev->next->next == NULL) + { + if(!strcmp(prev->value, target)) + { + struct car* last = prev->next; + free(prev); + bef_prev->next = last; + return first; + } + else if(!strcmp(prev->next->value, target)) + { + free(prev->next); + prev->next = NULL; + return first; + } + else + { + return first; + } + } + return first; }