Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. void copyLocalTreeRecursive(Node *x, RBTree *tree) {
  2. if (x->right != NIL)
  3. copyLocalTreeRecursive(x->right, tree);
  4.  
  5. if (x->left != NIL)
  6. copyLocalTreeRecursive(x->left, tree);
  7.  
  8. //If we find the key, we add the num_vegades of the local tree to the global tree,
  9. // if not, we create a new node in the global tree with the info of the local one
  10. RBData *nodeFound = findNode(tree, x->data->key);
  11. if (nodeFound) {
  12. nodeFound->num_vegades += x->data->num_vegades;
  13. } else {
  14. RBData *newNode = malloc(sizeof(RBData));
  15. newNode->key = malloc(sizeof(char *) * strlen(x->data->key));
  16. strcpy(newNode->key,x->data->key);
  17. newNode->num_vegades = x->data->num_vegades;
  18. insertNode(tree, newNode);
  19. }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement