clear
This commit is contained in:
parent
f5088bf6e8
commit
2a249097a5
@ -57,51 +57,29 @@ struct car* clear_train(struct car* first, const char* target) {
|
||||
if(result == 0){
|
||||
free(first);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return first;
|
||||
}
|
||||
}
|
||||
//struct car* this = first;
|
||||
/*if(first->next->next == NULL){
|
||||
int x = strcmp(this->next->value, target);
|
||||
if(x == 0){
|
||||
struct car* secondlast = first;
|
||||
while(this->next != NULL){
|
||||
secondlast = this;
|
||||
this = this->next;
|
||||
}
|
||||
if(this == first){
|
||||
first = NULL;
|
||||
}
|
||||
else{
|
||||
secondlast->next = NULL;
|
||||
}
|
||||
free(this);
|
||||
}
|
||||
} */
|
||||
|
||||
else{
|
||||
struct car* this = first;
|
||||
while(this->next!= NULL){
|
||||
int x = strcmp(this->value, target);
|
||||
struct car* prev = first;
|
||||
while(prev->next->next != NULL){
|
||||
int x = strcmp(prev->next->value, target);
|
||||
if(x == 0){
|
||||
struct car* curr = first;
|
||||
struct car* prev = NULL;
|
||||
if(first == this){
|
||||
first = this->next;
|
||||
free(this);
|
||||
//first->next = NULL;
|
||||
return first;
|
||||
}
|
||||
while(curr != this){
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
|
||||
}
|
||||
prev->next = curr->next;
|
||||
this->next = NULL;
|
||||
free(this);
|
||||
struct car* third = prev->next->next;
|
||||
free(prev->next);
|
||||
prev->next = third;
|
||||
return first;
|
||||
}
|
||||
this = this->next;
|
||||
prev = prev->next;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
int x = strcmp(prev->next->value, target);
|
||||
if(x == 0){
|
||||
free(prev->next);
|
||||
prev->next = NULL;
|
||||
return first;
|
||||
|
||||
}
|
||||
return first;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user