Watz wrong with this avl tree deletion code ??

Some nodes are getting deleted..

But then for other nodes the program stops working and terminates abruptly as such..

Getting some error report..

Cud someone help me out ??

Here is my c++ code for avl deletion..

```
void remove(const comparable & x,avlnode* & r)
{
if(r==NULL)
cout<<"\nNo element !!!";
else if(x<r->element)
{
remove(x,r->left);
if(avlheight(r->right)-avlheight(r->left)>1)
if(avlheight(r->right->right)>=avlheight(r->right->left))
rotatewithright(r);
else
doublewithright(r);
}
else if(x>r->element)
{
remove(x,r->right);
if(avlheight(r->left)-avlheight(r->right)>1)
if(avlheight(r->left->left)>=avlheight(r->left->right))
rotatewithleft(r);
else
doublewithleft(r);
}
else if(r->left!=NULL&&r->right!=NULL)
{
r->element=findmin(r->right)->element;
remove(r->element,r->right);
}
else
{
avlnode *oldnode=r;
r=(r->left!=NULL)?r->left:r->right;
delete oldnode;
}
r->height=max(avlheight(r->left),avlheight(r->right))+1;
}
```