clear train hell cv4

This commit is contained in:
Ivan Leichenko 2024-10-18 00:01:23 +02:00
parent 4d12d1de23
commit 090dc461f3

View File

@ -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;
}