12,747,207 members (28,469 online)
Rate this:
See more:
```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;
}```

Posted 29-Jan-13 9:03am
Updated 29-Jan-13 9:44am
v4
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.
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
J.Surjith Kumar 30-Jan-13 0:37am

Why you'r posting the same thing again and again in different question name.

Rate this:

## Solution 1

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

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

v2

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 158 Graeme_Grant 140 OriginalGriff 130 Maciej Los 85 NightWizzard 80
 OriginalGriff 3,658 Peter Leow 2,751 ppolymorphe 1,983 Karthik Bangalore 1,700 Richard MacCutchan 1,329