Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. void rotateRight(binaryTree*& root) {
  2.     if (root->left == nullptr)
  3.     {
  4.     //  cout << "Error" << endl;
  5.         return;
  6.     }
  7.     binaryTree* rootParent = root->parent;
  8.     binaryTree* left = root->left;
  9.     binaryTree* center=left->right;
  10.     /*if (root->left != nullptr) {
  11.         center = root->left->right;
  12.     } */
  13.     //Левое поддерево становится новой вершиной
  14.     left->parent = rootParent;
  15.     //Старая вершина становится правым поддеревом
  16.     left->right = root;
  17.     root->parent = left;
  18.  
  19.     //"Центральное" поддерево становится левым поддеревом для старой вершины
  20.    
  21.         root->left = center;
  22.    
  23.     if (center!=nullptr)
  24.     center->parent = root;
  25.     //Обновляем переменную вершину
  26.     if (left != nullptr) {
  27.         root = left;
  28.     }  
  29. }
  30. void rotateLeft(binaryTree*& root) {
  31.     if (root->right == nullptr)
  32.     {
  33.         //cout << "Error" << endl;
  34.         return;
  35.     }
  36.     binaryTree* rootParent = root->parent;
  37.     binaryTree* right = root->right;
  38.     binaryTree* center=  right->left;
  39.    
  40.    
  41.     right->parent = rootParent;
  42.     right->left = root;
  43.     root->parent = right;
  44.     root->right = center;
  45.    
  46.     if (center != nullptr)
  47.         center->parent = root;
  48.     root = right;
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement