From 98ba737b3fbc5c3e186699cc1635586a9c7d9407 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Wed, 4 Nov 2020 23:01:42 +0100 Subject: [PATCH] clear --- cv5/a_train.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cv5/a_train.c b/cv5/a_train.c index 027fbcd..0dca5c8 100644 --- a/cv5/a_train.c +++ b/cv5/a_train.c @@ -66,20 +66,20 @@ struct car* clear_train(struct car* first, const char* target) { while(this->next != NULL){ int x = strcmp(this->value, target); if(x == 0){ - struct car* curr = first; - struct car* prev = NULL; + struct car* prev = first; + struct car* node = first->next; if(first == this){ first = this->next; free(this); return first; } - while(curr != this){ - prev = curr; - curr = curr->next; + while(prev != NULL && node != NULL){ + prev->next = node->next; + free(node); + prev = prev->next; + if(prev != NULL) + node = prev->next; } - curr->next = prev->next; - this->next = NULL; - free(this); } this = this->next;