Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void rotateRight(binaryTree*& root) {
- if (root->left == nullptr)
- {
- // cout << "Error" << endl;
- return;
- }
- binaryTree* rootParent = root->parent;
- binaryTree* left = root->left;
- binaryTree* center=left->right;
- /*if (root->left != nullptr) {
- center = root->left->right;
- } */
- //Левое поддерево становится новой вершиной
- left->parent = rootParent;
- //Старая вершина становится правым поддеревом
- left->right = root;
- root->parent = left;
- //"Центральное" поддерево становится левым поддеревом для старой вершины
- root->left = center;
- if (center!=nullptr)
- center->parent = root;
- //Обновляем переменную вершину
- if (left != nullptr) {
- root = left;
- }
- }
- void rotateLeft(binaryTree*& root) {
- if (root->right == nullptr)
- {
- //cout << "Error" << endl;
- return;
- }
- binaryTree* rootParent = root->parent;
- binaryTree* right = root->right;
- binaryTree* center= right->left;
- right->parent = rootParent;
- right->left = root;
- root->parent = right;
- root->right = center;
- if (center != nullptr)
- center->parent = root;
- root = right;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement