void remove(Elem key)
{
Root=_remove(Root,key);
}
unsigned char height(){
return Root?Root->height:0;
}
AVL find(Elem key){ // search for key k in this tree
if(DEBUG){
printStr("Searching for '");
printChar((char)key);
if(empty()){
printStr("' in empty subtree\n");
}else {
printStr("' in subtree with root '");
printChar(root());
printStr("'\n");
}
}
node* n =_find(Root,key);
if(DEBUG)printStr("Search completed\n");
return AVL(n);
}
AVL copy(){// deep copy of tree
return AVL(_copy(Root));
}
AVL left(){// get left subtree
if(!Root){ std::cerr << "Error: left(null) \n"; exit(1); }
return AVL(Root->left);
}
AVL right(){// get right subtree
if(!Root){ std::cerr << "Error: right(null) \n"; exit(1); }
return AVL(Root->right);
}
Elem root(){// get root value
if(!Root){ std::cerr << "Error: root(null) \n"; exit(1); }
return Root->key;
}
void destroy(){//suicide
_destroy(Root);
Root=0;
}
};
#endif //CODE_AVLTREECLASS_H