question on AVL trees

N

Nobody

I have the following 2 functions done:

template <class Etype>
void S_Rotate_Left(Avl_Node<Etype> * & k2)
{
Avl_Node<Etype> *k1 = (Avl_Node<Etype>*)k2->Left;
k2->Left = k1->Right;
k1->Right = k2;
k2->Height = Max(Node_Ht(k2->Left), Node_Ht(k2->Right)) + 1;
k1->Height = Max(Node_Ht(k1->Left), k2->Height) + 1;
k2 = k1;
}

template <class Etype>
void D_Rotate_Left(Avl_Node<Etype> * & k3)
{
S_Rotate_Right((Avl_Node<Etype> * &)k3->Left);
S_Rotate_Left(k3);
}

I obviously need S_Rotate_Right and D_Rotate_Right. I am told these are
"symetrical"... whatever that means, LOL.

Are the functions below correct?

template <class Etype>
void S_Rotate_Right(Avl_Node<Etype> * & k2)
{
Avl_Node<Etype>* k1 = (Avl_Node<Etype>*)k2->Right;
k2->Right = k1->Left;
k1->Left = k2;
k2->Height = Max(Node_Ht(k2->Right), Node_Ht(k2->Left)) + 1;
k1->Height = Max(Node_Ht(k1->Right), k2->Height) + 1;
k2 = k1;
}

template <class Etype>
void D_Rotate_Right(Avl_Node<Etype> * & k3)
{
S_Rotate_Left((Avl_Node<Etype> * &)k3->Right);
S_Rotate_Right(k3);
}

Thanks for the help :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top