int searchAVL_Tree(struct AVL_Tree *tree, void *elem) { if (tree == NULL) return 0; if (tree->root == NULL) return 0; struct AVL_TreeNode *no_aux = tree->root; if (*(int*)elem == *(int*)no_aux->elem) return 1; //Achou struct AVL_Tree *arvore_aux = criarArvore(); if (*(int*)elem < *(int*)no_aux->elem) { arvore_aux->root = no_aux->left; return searchAVL_Tree(arvore_aux, elem); } if (*(int*)elem > *(int*)no_aux->elem) { arvore_aux->root = no_aux->right; return searchAVL_Tree(arvore_aux, elem); } return 0; //Nao Achou }
int searchAVL_Tree(struct AVL_Tree *tree, void *elem) { if (!tree)return 0; AVL_TreeNode *x = tree->root; if (!tree->root)return 0; if (*(int*) elem == *(int*) tree->root->elem) return 1; //Qual o sentido da busca retornar 1? Não deveria retornar o elemento ou índice? else { if (*(int*) elem < *(int*) x->elem) { AVL_Tree * p = (AVL_Tree*) malloc(sizeof (AVL_Tree)); p->root = x->left; return searchAVL_Tree(p, elem); } else if (*(int*) elem > *(int*) x->elem) { AVL_Tree *p = (AVL_Tree*) malloc(sizeof (AVL_Tree)); p->root = x->right; return searchAVL_Tree(p, elem); } } return 0; }