Well I suppose I could come up with an example you could use. Not much of this will look familiar but you will get the idea. You should probably use a more C++ like approach to this anyway.
You need to build a class for your linked list. First, concentrate on creating and then deleting nodes. After you get that working, then you have a solid foundation to build upon, because you can properly make and destroy a list, and it will be time to move on to writing the algorithms you need.
You will copy your data into a list.
Then you will apply your filter like this, in pseudocode:
Code:
procedure apply_filter ( this_filter_func f ) :
i = 0;
while i < list.size() :
if f( list( i ) ) :
display list( i )
endif
endwhile
done
Hopefully that's not too bad.
For a more concrete example, look at the C++ STL:
Code:
#include <list>
#include <algorithm>
#include <string>
struct node
{
std::string name;
std::string dept;
float salary;
// other members ...
};
bool filter ( const node & n )
{
return n.salary > 100.0f || n.dept != "SALES";
}
int main()
{
// copy your data ubto a linked list:
node data[] = {
{ "Joe", "SALES", 99.0f }, { "Sam", "MGMT", 200.0f },
{ "Bob", "ACCNT", 80.0f }, { "Oliver", "MGMT", 399.0f }
};
std::list<node> full_list( data, data+4 );
std::list<node> poor_list( full_list.size() );
// apply your filter:
std::list<node>::iterator last_copied = std::remove_copy_if(
full_list.begin(), full_list.end(), poor_list.begin(), filter );
// fixing the list size:
poor_list.erase( last_copied, poor_list.end() );
}
And now, if you look, the poor_list only contains the poor salesman named Joe.
I dunno if I expressed myself very well, but this is the sort of approach a more experienced person would take. If you want to build the linked list data structure yourself (always a fun, learning exercise), go ahead. Just make sure that you build appropriate functions to make a list, apply your filter to items in that list, and display the result.