Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TreeLink deleteNode(TreeLink t, char* word){
- TreeLink temp;
- if (t == NULL){
- return NULL;
- }
- else if (strcmp(word, t->key) < 0){
- t->left = deleteNode(t->left, word);
- // if (depth(t->right) - depth(t->left) == 2){
- // if (strcmp(word, t->right->key) < 0){
- // t = leftRotate(t);
- // }
- // else{
- // t = rightLeftRotate(t);
- // }
- // }
- }
- else if (strcmp(word,t->key) > 0){
- t->right = deleteNode(t->right, word);
- // if (depth(t->left) - depth(t->right) == 2){
- // if (strcmp(word, t->left->key) > 0){
- // rightRotate(t);
- // }
- // else{
- // t = leftRightRotate(t);
- // }
- // }
- }
- else{// if (strcmp(word, t->key) == 0){
- //if (t->left == NULL && t->right == NULL){ //if we delete a leaf
- //deletelist(t->rowlist);
- // free(t);
- //t = NULL;
- // }
- if (t->left != NULL && t->right != NULL){ // if we delete node with 2 childs
- temp = maxValue(t->left); // we choose biggest element at the left subtree
- t->key = temp->key;
- t->rowlist = temp->rowlist;
- //deletelist(temp->rowlist);
- free(temp);
- t->left = deleteNode(t->left, t->key); // continue so we can fall into one of the o
- }
- else{ // when we want to delete a node with no childs or 1 child.
- temp = t;
- if (t->left == NULL){
- t = t->right; // linking nodes together
- }
- else if (!t->right == NULL){
- t = t->left; // linking nodes together
- }
- //deletelist(temp->rowlist);
- free(temp);
- }
- }
- return t;
- }
Add Comment
Please, Sign In to add comment