
//(c)Terminator
#include <iostream>
using namespace std;


struct node {
	int   val;
	node* next;
};

static void fill(node** lst, const int* fa, const int* la);
static void clear(node* lst);
static void remove_before(node** lst, bool (*pfn)(int));


bool  func_un(int val){ return (val > 0); }



int main(void){
	node* lst = NULL;

	int a[] = { -10, -20, 30, 40 };
	fill(&lst, a, a + sizeof(a)/sizeof(a[0]));
	remove_before(&lst, func_un);

	for(const node* i = lst; i != NULL; i = i->next)
		cout << i->val << endl;

	clear(lst);
	return 0;
}




//заполнение списка массивом
static void fill(node** lst, const int* fa, const int* la){
	node* h = NULL, *t = NULL;

	while(fa != la){
		node* p = new node();
		p->next = NULL;
		p->val  = *fa++;

		if(h == NULL)
			h = t = p;
		else {
			t->next = p;
			t = p;
		}
	}
	*lst = h;
}



//чистка всего списка
static void  clear(node* lst){
	node* tmp;
	while(lst != NULL){
		tmp = lst;
		lst = lst->next;
		delete tmp;
	}
}



//удаление элемента по компаратору
static void  remove_before(node** lst, bool (*pfn)(int)){
	node* p = *lst;

	if(p != NULL){
		while((p->next != NULL) && !(*pfn)(p->next->val)){
			lst = &p->next;
			p   = p->next;
		}

		if(p->next != NULL){
			*lst = p->next;
			delete p;
		}
	}
}