c++ - Trying to rotate an AVL Tree, height issue -
c++ - Trying to rotate an AVL Tree, height issue -
i'm trying implement avl tree, can't pass if statement
void avl::insert(node **r,node data){ // insert(&root,data) if(!(*r)){ (*r)= new node(); (**r) = data; if( abs( height((*r)->left) - height((*r)->right) ) > 1 ){...} ... ... } else if(data.value<(*r)->value) insert(&((*r)->left),data); else insert(&((*r)->right),data); }
my height function:
int avl::height(node *p){ if (!p) homecoming 0; int left = height(p->left); int right = height(p->right); homecoming (1 + max(left,right)); }
i don't know i'm doing wrong, should work fine. tried output "test" before if statement = if(abs( height((*r)->left) - height((*r)->right) ) >1 ) , works perfect, tried within statement , never go in.
my actual tree:
100 90 80 70
should this:
90 80 100 70
if need more info, allow me know.
c++ data-structures tree binary-tree avl-tree
Comments
Post a Comment