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;
}
第一次在Insert
,root
是NULL,但是當我調試時,它跳過root == null
。這是怎麼回事?NULL指針問題?
謝謝,簡單而有用的答案:) – nXqd 2009-11-23 05:29:14