Search code examples
csortingbinary-search-treegnu

How to use libavl?


I'm trying to use GNU libavl (http://adtinfo.org/) for one of my academic projects. I need a simple enough tutorial on how to use the BST(Binary search tree) implementation provided by the library. What I need to do is sort a (key,value) pair(about 30000 strings and there frequencies) using a BST according to the value. Although the library is well documented, it doesn't give any straight foreword answer to my question and I don't have the time to read trough all the documentation and test code. I would like to know if there is much faster way to do the sorting.


Solution

  • int main(int argc, char **argv)
    {
        tree *avl_tree = NULL;
        struct data tmp;
        unsigned result;
    
        (void) argc;
        (void) argv;
    
        // Initialize a new tree with our three previously defined
        // functions to store data structure.
        avl_tree = init_dictionnary(data_cmp, data_print, data_delete, data_copy);
    
        tmp.key = 42;
        tmp.value = 4242;
    
        // Add element {42, 4242} in our tree.
        result = insert_elmt(avl_tree, &tmp, sizeof(struct data));