Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 29-Jan-13 9:03am
Edited 29-Jan-13 9:44am
v4
Comments
OriginalGriff at 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 at 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 at 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 at 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 at 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
J.Surjith Kumar at 30-Jan-13 0:37am
   
Why you'r posting the same thing again and again in different question name.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 230
2 DamithSL 150
3 Dave Kreskowiak 110
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,740
1 DamithSL 5,644
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,011
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100