- if(c > 0) {
- leftbottom->right = child;
- child->parent = leftbottom;
- leftbottom = child;
-
- node->right = child->left;
- child->left = node;
- node->parent = child;
- node = child->right;
- child->right = NULL;
- } else if (c < 0) {
- if(!child->left)
- break;
-
- rightbottom->left = child;
- child->parent = rightbottom;
- rightbottom = child;
-
- leftbottom->right = node;
- node->parent = leftbottom;
- leftbottom = node;
-
- node->right = NULL;
- node = child->left;
- child->left = NULL;
- } else {
- leftbottom->right = node;
- node->parent = leftbottom;
- leftbottom = node;
-
- node->right = NULL;
- child->parent = NULL;
- node = child;
- break;
- }
+ if((root->right = child->left))
+ child->left->parent = root;
+
+ child->left = root;
+ root->parent = child;
+
+ child->right = NULL;
+ grandchild->parent = NULL;
+
+ root = grandchild;
+ } else if (c < 0 && (grandchild = child->left)) {
+ rightbottom->left = child;
+ child->parent = rightbottom;
+ rightbottom = child;
+
+ child->left = NULL;
+ grandchild->parent = NULL;
+
+ leftbottom->right = root;
+ root->parent = leftbottom;
+ leftbottom = root;
+
+ root->right = NULL;
+
+ root = grandchild;