-1
I have the following function
NOTE: In this function is only the first case, so it doesn’t get too big. Since the error occurs right at the first insertion.
int insertAVL_TreeR(struct AVL_TreeNode **node, void *elem, int *h) {
if (!node) {//se o nó não existir, é criado um novo no
AVL_TreeNode *novo = (AVL_TreeNode*) malloc(sizeof (AVL_TreeNode));
novo->elem = elem;
novo->fb = 0;
novo->left = NULL;
novo->right = NULL;
node = novo;
*h = 1; //haverá mudança na altura
} else {
Which is called in right function
int insertAVL_Tree(struct AVL_Tree *tree, void *elem) {
if (!tree)return 0;
int *h = (int*) malloc(sizeof (int));
*h = 1;
AVL_TreeNode **p = &tree->root;
int x = insertAVL_TreeR(*p, elem, h); //a chamada se dá nesta linha
return x;
}
I want to know what the right way to move this pointer to pointer is. Because inside the function I get a Warning and everything goes well, but when it goes back to main, avl->root (previously initialized as NULL) goes on pointing to NULL.
My structs are these
typedef struct AVL_TreeNode
{
void *elem;
struct AVL_TreeNode *left;
struct AVL_TreeNode *right;
int fb;
}AVL_TreeNode;
and
typedef struct AVL_Tree
{
struct AVL_TreeNode *root;
}AVL_Tree;