void _addRedBlackTree(Node **nodePtr, Node *newNode) { if(*nodePtr == NULL) { *nodePtr = newNode; return; } if(newNode->data < (*nodePtr)->data) { _addRedBlackTree(&(*nodePtr)->left, newNode); solveAddViolationForNewNodeLessThan(&(*nodePtr)); // this function purpose is to solve the violation for those new node data that is less than the nodePtr data solveAddViolationFor4NodeLessThan(&(*nodePtr)); } else { _addRedBlackTree(&(*nodePtr)->right, newNode); solveAddViolationForNewNodeMoreThan(&(*nodePtr)); // this function purpose is to solve the violation for those new node data that is more than the nodePtr data solveAddViolationFor4NodeMoreThan(&(*nodePtr)); } }
void _addRedBlackTree(Node **rootPtr, Node *newNode){ Node *root = *rootPtr; if(root == NULL){ *rootPtr = newNode; return; } if(newNode->data == root->data) Throw(ERR_EQUIVALENT_NODE); if(newNode->data < root->data) _addRedBlackTree( &root->left , newNode); if(newNode->data > root->data) _addRedBlackTree( &root->right, newNode); if(!( (*rootPtr)->right && (*rootPtr)->left) ) // if root->right && root-> left are null return; else if( root->left->color == root->right->color && ( root->left->left || root->left->right || root->right->right || root->right->left )){ root->color = 'r'; root->left->color = 'b'; root->right->color = 'b'; } }
void _addRedBlackTree(Node **rootPtr, Node *newNode, int (*compareNode)(void *data, void *object)){ Node *root = *rootPtr; if(root == NULL){ *rootPtr = newNode; return; } if(compareNode(root->data, newNode->data) == 0) Throw(ERR_EQUIVALENT_NODE); else if(compareNode(root->data, newNode->data) == 1) _addRedBlackTree( &root->right, newNode, compareNode); else if(compareNode(root->data, newNode->data) == -1) _addRedBlackTree( &root->left , newNode, compareNode); if(!( (*rootPtr)->right && (*rootPtr)->left) ) // if root->right && root-> left are null return; else if( root->left->color == root->right->color && ( root->left->left || root->left->right || root->right->right || root->right->left )){ root->color = 'r'; root->left->color = 'b'; root->right->color = 'b'; } }
void addRedBlackTree(Node **rootPtr, Node *newNode, int (*compareNode)(void *data, void *object)){ _addRedBlackTree(rootPtr, newNode, compareNode); TreeBalancing( rootPtr); (*rootPtr)->color = 'b'; }
void addRedBlackTree(Node **nodePtr, Node *newNode) { _addRedBlackTree(nodePtr, newNode); (*nodePtr)->color = 'b'; }
void addRedBlackTree(Node **rootPtr, Node *newNode){ _addRedBlackTree(rootPtr, newNode); restructureUnBalanceTree( rootPtr); (*rootPtr)->color = 'b'; }