Click here to Skip to main content
12,747,207 members (28,469 online)
Rate this:
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
Updated 29-Jan-13 9:44am
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.
J.Surjith Kumar 30-Jan-13 0:37am
Why you'r posting the same thing again and again in different question name.

1 solution

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

Solution 1

Consult "Eternally confuzzled" about data structures like AVL trees:[^]

Tip: Forget about AVL trees and go for AA trees instead.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2017
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