void Insert(AVLnode * & root, string X)
{
if ( root == NULL)
{
root = GetNode(X);
}
else if ( root->info > X )
{
Insert(root->left,X);
if ( height(root->left) - height(root->right) == 2 )
if ( X < root->left->info )
RotateRR(root);
else
RotateLR(root);
}
else if ( root->info < X )
{
Insert(root->right,X);
if ( height(root->right) - height(root->left) == 2 )
if ( X > root->right->info )
RotateRR(root);
else
RotateLR(root);
}
root->height = max( height(root->left), height(root->right) )+1;
}
AVLnode* find(AVLnode* root,string X)
{
if (!root) return 0;
if ( root->info == X )
return root;
else if (root->info < X)
find(root->left,X);
else if (root->info > X)
find(root->right,X);
return 0;
}
int main(int argc,char* argv)
{
AVLnode* Dic;
Insert(Dic,"adf");
return 0;
}
The first time in Insert
, root
is NULL but when I debug, it skips root == null
. What's going on?