Advertisement
gracefu

Untitled

Oct 10th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. while (node != NULL) {
  2. node->balance += d_balance
  3. if (node->balance == 0) {
  4. return;
  5. } else if (node->balance == -2) {
  6. if (node->left->balance == -1) {
  7. Tree_RotateRight (t, node);
  8. } else {
  9. Tree_RotateLeftRight (t, node);
  10. }
  11. return;
  12. } else if (node->balance == 2) {
  13. if (node->right->balance == 1) {
  14. Tree_RotateLeft (t, node);
  15. } else {
  16. Tree_RotateRightLeft (t, node);
  17. }
  18. return;
  19. }
  20. Node parent = node->parent;
  21. if (parent != NULL) {
  22. d_balance = (parent->left == node) ? -1 : 1;
  23. }
  24. node = parent;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement