Update cv4/a_train.c

This commit is contained in:
Yurii Yakovenko 2024-10-24 21:22:04 +00:00
parent 6918bd4763
commit 6cf706c19d

View File

@ -3,6 +3,7 @@
struct car* add_car(struct car* first,const char* target)
{
struct car* ret=first;
@ -29,7 +30,6 @@ void print_train(struct car* first)
{
if(first==NULL)
{
return;
}
@ -39,7 +39,6 @@ void print_train(struct car* first)
first=first->next;
if(first) printf("->");
}while(first!=NULL);
}
void cancel_train(struct car* first)
@ -63,6 +62,7 @@ struct car* clear_train(struct car* first, const char* target)
return first;
}
while(strcmp(first->value, target)==0)
{
t=first;
@ -79,21 +79,19 @@ struct car* clear_train(struct car* first, const char* target)
ptr=first;
do
while (ptr->next != NULL)
{
if(strcmp(ptr->next->value, target)==0)
if (strcmp(ptr->next->value, target) == 0)
{
t=ptr->next;;
ptr->next = ptr -> next->next;
t = ptr->next;
ptr->next = ptr->next->next;
free(t);
}
else
{
ptr = ptr -> next;
ptr = ptr->next;
}
}
}while(ptr->next);
return first;
}