Initializacia
This commit is contained in:
parent
9cd93271e1
commit
6c79f0d250
@ -43,27 +43,27 @@ void cancel_train(struct car* first) {
|
||||
|
||||
|
||||
struct car* clear_train(struct car* first, const char* target) {
|
||||
// if (first = NULL){
|
||||
// return NULL;
|
||||
// }
|
||||
// struct car* current = first, new_first = first;
|
||||
// if (first != NULL){
|
||||
// if(strcmp(first->destination, target) == 0){
|
||||
// new_first = new_first->next;
|
||||
// free(first);
|
||||
// first = new_first;
|
||||
// }
|
||||
// }
|
||||
if (first = NULL){
|
||||
return NULL;
|
||||
}
|
||||
struct car* current = first, new_first = first;
|
||||
if (first != NULL){
|
||||
if(strcmp(first->destination, target) == 0){
|
||||
new_first = new_first->next;
|
||||
free(first);
|
||||
first = new_first;
|
||||
}
|
||||
}
|
||||
|
||||
// while (first->next != NULL) {
|
||||
// current = first->next;
|
||||
// if (strcmp(current->destination, target) == 0) {
|
||||
// first->next = current->next;
|
||||
// free(current);
|
||||
// } else {
|
||||
// first = current;
|
||||
// }
|
||||
// }
|
||||
// return new_first;
|
||||
while (first->next != NULL) {
|
||||
current = first->next;
|
||||
if (strcmp(current->destination, target) == 0) {
|
||||
first->next = current->next;
|
||||
free(current);
|
||||
} else {
|
||||
first = current;
|
||||
}
|
||||
}
|
||||
return new_first;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user