question on AVL trees

Discussion in 'C++' started by Nobody, Dec 24, 2004.

  1. Nobody

    Nobody Guest

    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 :)
     
    Nobody, Dec 24, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nobody
    Replies:
    1
    Views:
    1,506
    Dave O'Hearn
    Dec 26, 2004
  2. Nobody
    Replies:
    3
    Views:
    1,448
    Ben Pfaff
    Dec 29, 2004
  3. Paul Emmons

    AVL trees

    Paul Emmons, Jul 5, 2003, in forum: C Programming
    Replies:
    1
    Views:
    601
    Mike Wahler
    Jul 5, 2003
  4. Evangelista Sami

    question on avl trees

    Evangelista Sami, Nov 21, 2003, in forum: C Programming
    Replies:
    1
    Views:
    313
    Noah Roberts
    Nov 21, 2003
  5. jacob navia

    Binary search trees (AVL trees)

    jacob navia, Jan 3, 2010, in forum: C Programming
    Replies:
    34
    Views:
    1,477
    Dann Corbit
    Jan 8, 2010
Loading...

Share This Page