AfanasevGad7

This is a task for our favourite professor
git clone git://git.stellar-nexus.ru/AfanasevGad7
Log | Files | Refs

commit 2f1dfae444fe891f8e899b6970f75ac86cb6f53f
parent df287f2e67cbd2671be31b95df12b8e5cdcf1bb6
Author: Plat <plat@stellar-nexus.ru>
Date:   Thu,  6 Nov 2025 18:38:26 +0000

Changed rotation logic

Diffstat:
Mrb.c | 31++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/rb.c b/rb.c @@ -34,28 +34,25 @@ add(Node *root, int val) } Node * -right_turn(Node *root) +left_turn(Node *root) { - if (!root || !root->left) - return root; - - Node *buf = root->left; - root->left = buf->right; - buf->right = root; - return buf; + Node *n = root->right; + root->right = n->left; + n->left = root; + SET_COLOR(n, COLOR(root)); + SET_COLOR(root, RED); + return n; } - Node * -left_turn(Node *root) +right_turn(Node *root) { - if (!root || !root->right) - return root; - - Node *buf = root->right; - root->right = buf->left; - buf->left = root; - return buf; + Node *n = root->left; + root->left = n->right; + n->right = root; + SET_COLOR(n, COLOR(root)); + SET_COLOR(root, RED); + return n; } Node *