История изменений
Исправление MKuznetsov, (текущая версия) :
можно где-то так:
Node *filter(Node *list,int (*condition)(Node *))
{
Node *head=NULL,*tail=NULL;
inline Node* filter_next1(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
head=tail=curr;
}
return next;
}
inline Node* filter_next2(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
tail=tail->next=curr;
}
return next;
}
while(head==NULL && list!=NULL)
list=filter_next1(list,list->next);
while(list!=NULL)
list=filter_next2(list,list->next);
if (tail!=NULL)
tail->next=NULL;
return head;
}
Исправление MKuznetsov, :
можно где-то так:
Node *filter(Node *list,int (*condition)(Node *))
{
Node *head=NULL,tail=NULL;
inline Node* filter_next1(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
head=tail=curr;
}
return next;
}
inline Node* filter_next2(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
tail=tail->next=curr;
}
return next;
}
while(head==NULL && list!=NULL)
list=filter_next1(list,list->next);
while(list!=NULL)
list=filter_next2(list,list->next);
if (tail!=NULL)
tail->next=NULL;
return head;
}
Исходная версия MKuznetsov, :
можно где-то так:
Node *filter(Node *list,int (*condition)(Node *))
{
Node *head=NULL,tail=NULL;
inline int filter_next1(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
head=tail=curr;
}
return next;
}
inline int filter_next2(Node *curr,Node *next) {
if (condition(curr)) {
free(curr);
} else {
tail=tail->next=curr;
}
return next;
}
while(head==NULL && list!=NULL)
list=filter_next1(list,list->next);
while(list!=NULL)
list=filter_next2(list,list->next);
if (tail!=NULL)
tail->next=NULL;
return head;
}