Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
node* rightrotate(struct node *y)
{
    struct node *x = y->left;
    struct node *z = x->right;

    x->right = y;
    y->left = z;

    y->h = max(h(y->left), h(y->right))+1;
    x->h = max(h(x->left), h(x->right))+1;

    return x;
}
node* leftrotate(struct node *x)
{
    struct node *y = x->right;
    struct node *z = y->left;

    y->left = x;
    x->right = z;

    y->h = max(h(y->left), h(y->right))+1;
    x->h = max(h(x->left), h(x->right))+1;

    return y;
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 29-Jan-13 8:44am
v4
Comments
OriginalGriff 29-Jan-13 14:22pm    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
All that you have done, is say "I don't think it's right" and throw us a badly commented code dump.
Cut the code down the to relevant code fragments, tell us what you expect and what happens, and we may be able to help.
Use the "Improve question" widget to edit your question and provide better information.
mahla.r_1993 29-Jan-13 14:37pm    
i write just left and right rotate plz read my code and say me what is wrong in this part ??? i want to write a code for avl tree
OriginalGriff 29-Jan-13 14:44pm    
What does it do that it shouldn't, or not do that it should?
If you don't tell us, we have to guess - and that doesn't please anyone!
mahla.r_1993 29-Jan-13 14:53pm    
it use in avl tree
for example when i get 10 20 30 in avl tree
with right rotate i get 20 10 30
Andreas Gieriet 29-Jan-13 14:59pm    
Use the debugger!
And: *Please* answer the counter question before jumping away... As mentioned above: the given code contains no clue where and how you enter the data and where and how you output the data! No clue what avl tree is, no clue what max() and h() functions do exactly, etc.
Andi

1 solution

Consult "Eternally confuzzled" about data structures like AVL trees:

http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_avl.aspx[^]

Tip: Forget about AVL trees and go for AA trees instead.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900