0

I´m trying to develop an avl tree in C++, but I have problems with my rotation algorithm. I have try ALL the algorithms I could find on the web, but none of they works and I can´t see where is the problem.

Here is my structure:

```
typedef struct node{
int data;
int fe;
struct node *left;
struct node *right;
struct node *father;
}node;
typedef struct node *avl;
```

This is my implementation of the simple rigth rotation, which recieves a pointer of the node where is the unbalance (*fot), and I create three pointers:

*a if the fot node recieved is not the father of the tree.

*p will be replacing *fot in the rotation

*q will be the left child of *fot, replacing *p

```
void SRR(avl *fot){
avl *a; a=new avl; *a=NULL;
avl *p; p=new avl; *p=NULL;
avl *q; q=new avl; *q=NULL;
&*a= &(*fot);
*p= (*fot)->left;
*q= (*p)->right;
(*fot)->left= *q;
if (q)
(*q)->father= *fot;
(*p)->right= (*fot);
(*fot)->father= *p;
if ((*a)->father->data==(*a)->data)
(*p)->father=*p;
else
(*p)->father=(*a)->father;
(*fot) = *p;
*p = (*fot)->rigth;
*q = (*p)->left;
}
```

No matter how hard I try, I can´t see where is the problem, my program freezes and I don't know where. Please, can anyone help me to find the problem? :'( What's wrong in my algorithm?