Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TREE* mergeTrees(TREE* root1 ,TREE* root2) // O(h), h = height of one of the trees
- {
- NODE2* newRoot, fatherMinimunRight;
- TREE* newTree;
- // find the minimun of the right tree
- newRoot = findMinimum(root2);
- // the father of the minimumRight should point to null.
- fatherNewRoot = father(root2->head.left, newRoot->key);
- fatherNewRoot->left = NULL;
- // newRoot should point from right to root2
- newRoot->right = root2->head.left;
- // newRoot should point from left to root1
- newRoot->left = root1->head.left;
- // create the new tree
- if (!(newTree = (TREE*)malloc(sizeof(TREE)))) return NULL; // allocation error
- if (T_init(newTree) == FALSE)
- {
- return NULL;
- }
- newTree->head.left = newRoot;
- return newTree;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement