Guest User

Untitled

a guest
May 23rd, 2019
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void leftRotate(TreeNode x) {
  2. TreeNode y = x.right; //Bestimme y, um es zu tauschen
  3. x.right = y.left; // XrightPointer zeigt auf YleftPointer
  4. if (y.left != _nil) {
  5. y.left.p = x;
  6. }
  7. y.p = x.p;
  8. if (x.p == _nil) {
  9. _root = y;
  10. } else if (x == x.p.left) {
  11. x.p.left = y;
  12. } else {
  13. x.p.right = y;
  14. }
  15. y.left = x;
  16. x.p = y;
  17. }
  18.  
  19. public void rightRotate(TreeNode x) {
  20. TreeNode y = x.left;
  21. x.left = y.right;
  22. if (y.right != _nil) {
  23. y.right.p = x;
  24. }
  25. y.p = x.p;
  26. if (x.p == _nil) {
  27. this._root = y;
  28. } else if (x == x.p.right) {
  29. x.p.right = y;
  30. } else {
  31. x.p.left = y;
  32. }
  33. y.right = x;
  34. x.p = y;
  35. }
RAW Paste Data