#include <drlibs/sortedlist.dr.h>
#include <iostream>
#include <string>
using namespace std;
/* This simple function will be used to print the list of strings. */
void echo (string &data) {
    cout << data << endl;
}
/* This function will be used to set the order of the list of strings. */
bool cmp (string &a, string &b) {
/* It is different that the default. */
    return (a.size () >= b.size ());
}
/* The parameters taken by the program will be used to feed the lists. */
int main (int counter, char **params) {
/* A sorted list as a pointer to hold the parameters. */
    SortedList<string> *strlist = new SortedList<string>;
/* Another sorted list of integers to hold parameters' sizes. */
    SortedList<int> sizes;
/* Setting the order for the list of strings. As you can see, the other *
 * sorted list will use the default function, something like "a < b". */
    strlist->setCompareFunction (cmp);
/* Feeding the lists. */
    for (int i=0; i<counter; i++) {
        strlist->add (params [i]);
        sizes.add (strlen(params [i]));
    }

    cout << "Sizes gotten:" << endl;
/* Printing all the sizes one by one. */
    sizes.rewind ();
    for (int i=0; i<sizes.length (); i++) {
        cout << sizes.get () << endl;
        sizes.seekNext ();
    }

    cout << "Parameters gotten:" << endl;
/* Using one of the iterative methods. */
    strlist->listDo (echo);

    cout << "Sizes again:" << endl;
/* The same printing of sizes, but with a little difference. */
    sizes.rewind ();
    for (int i=0; i<sizes.length (); i++) {
        cout << sizes.getJump () << endl;
    }

    cout << endl;

    return 0;
}