#include <drlibs/sortedlist.dr.h>
#include <iostream>
#include <string>
using namespace std;
class rec {
    private:
        int ID;
        string NAME;
    public:
        rec (int x, string y) { ID = x; NAME = y; }
        int id () { return ID; }
        string name () { return NAME; }
};
void echo (rec *&data) {
    cout << "[" << data->id () << "] " << data->name ()<< endl;
}
bool cmp (rec *&a, rec *&b) {
    return (a->id () < b->id ());
}
bool cmp2 (rec *&a, rec *&b) {
    return (a->name () < b->name ());
}
bool sel (rec *&data) {
    return (data->name().size () > 4);
}
int main () {
    SortedList<rec*> *reclist = new SortedList<rec*>;
/* Ordering records by the ID number. */
    reclist->setCompareFunction (cmp);

    reclist->add (new rec (63, "Mike"));
    reclist->add (new rec (12, "John"));
    reclist->add (new rec (53, "Richard"));
    reclist->add (new rec (86, "George"));
    reclist->add (new rec (83, "Robert"));
    reclist->add (new rec (80, "Daniel"));
    reclist->add (new rec (96, "Brad"));
    reclist->add (new rec (98, "Matt"));
    reclist->add (new rec (78, "Joan"));
    reclist->add (new rec (21, "Joe"));
    reclist->add (new rec (10, "Bob"));
/* Printing the list. */
    reclist->listDo (echo);
    cout << endl;
/* Creating a new list to hold a selection. */
    SortedList<rec*> *partlist = new SortedList<rec*>;
/* Setting the the compairer function, the order will be the names. */
    partlist->setCompareFunction (cmp2);
/* Selecting those records that has a name with more than four charcaters. */
    partlist->add (*reclist->listSelect (sel));
/* Printng the selection. */
    partlist->listDo (echo);

    return 0;
}