Initializacia
This commit is contained in:
parent
91662d4ed8
commit
c79715105c
@ -33,37 +33,40 @@ void print_train(struct car* first) {
|
||||
}
|
||||
|
||||
void cancel_train(struct car* first) {
|
||||
// struct car* current = first;
|
||||
// while(first != NULL){
|
||||
// current = current->next;
|
||||
// free(first);
|
||||
// first = current;
|
||||
// }
|
||||
struct car* current = first;
|
||||
while(first != NULL){
|
||||
current = current->next;
|
||||
free(first);
|
||||
first = current;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct car* clear_train(struct car* first, const char* target) {
|
||||
if (first = NULL){
|
||||
if (first == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
struct car* current = first, new_first = first;
|
||||
if (first != NULL){
|
||||
if(strcmp(first->value, target) == 0){
|
||||
new_first = new_first->next;
|
||||
free(first);
|
||||
first = new_first;
|
||||
}
|
||||
|
||||
struct car* current = first;
|
||||
struct car* previous = NULL;
|
||||
|
||||
while (current != NULL && strcmp(current->value, target) == 0) {
|
||||
struct car* temp = current;
|
||||
first = current->next;
|
||||
current = first;
|
||||
free(temp);
|
||||
}
|
||||
|
||||
while (first->next != NULL) {
|
||||
current = first->next;
|
||||
while (current != NULL) {
|
||||
if (strcmp(current->value, target) == 0) {
|
||||
first->next = current->next;
|
||||
previous->next = current->next;
|
||||
free(current);
|
||||
current = previous->next;
|
||||
} else {
|
||||
first = current;
|
||||
previous = current;
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
return new_first;
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user