0

I can't understand the argument, i've seen it for the 1st time.

below is the structure:

typedef struct node{
void* dataPtr;
struct node* left;
struct node* right;
}NODE;

typedef struct{
    int count;
    int (*compare)(void* argu1, void* argu2);
    NODE* root;
}BST_TREE;

This is Prototype:

BST_TREE* BST_Create(int (*compare)(void* argu1, void* argu2));

This is Function:

BST_TREE* BST_Create(int (*compare)(void* argu1, void *argu2)){
    BST_TREE* tree;
    tree = (BST_TREE*)malloc(sizeof(BST_TREE));
    if(tree){
        tree->root = NULL;
        tree->count = 0;
        tree->compare = compare;
    }
    return tree;
}
  • Do you realize that it is a pointer to a function? If not, that's what it is. You can now search for the ins and outs of pointers to functions. If you know it's a pointer to a function, what's the problem? It is presumably used to ensure that elements in the BST are in the correct order — it compares two nodes given pointers to the nodes, identifying which comes first and which comes second, or that they're equal. – Jonathan Leffler Nov 21 '18 at 17:25
  • Get a good book or find a good tutorial, one that explains *function pointers*. – Some programmer dude Nov 21 '18 at 17:25
  • By the way, considering that you [should not cast `malloc` in C](https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc/605858#605858), the code you found might not be the best to learn from. – Some programmer dude Nov 21 '18 at 17:26

0 Answers0