diff --git a/cv4/a_train.c b/cv4/a_train.c index 647d575..bab6039 100644 --- a/cv4/a_train.c +++ b/cv4/a_train.c @@ -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) @@ -62,38 +61,37 @@ struct car* clear_train(struct car* first, const char* target) { return first; } - + + while(strcmp(first->value, target)==0) { t=first; first=first->next; free(t); - + if(first==NULL) { - + return NULL; } } - - ptr=first; - do + ptr=first; + + 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; } -