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