I have the following function
NOTE: In this function is only the first case, not to get too large. Since the error occurs 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 {
What is called inside 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 the correct way to pass this pointer to pointer. For inside the function I get a warning and everything works fine, but when it goes back to main, avl-> root (previously initialized as NULL) keeps pointing to NULL.
My structs are esssa
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;