Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Tree& Tree::operator+ (Tree& other_tree){
  2. Tree* first_tree = new Tree(*this);
  3. Tree* second_tree = new Tree(other_tree);
  4.  
  5. if (first_tree->root != NULL){
  6. Node* parent_of_leaf = &(first_tree->findParentOfLeaf());
  7. if (!parent_of_leaf->isLeaf()){
  8. int number_of_child_leaf = parent_of_leaf->whichChildIsLeaf();
  9. delete parent_of_leaf->children[number_of_child_leaf];
  10. parent_of_leaf->children[number_of_child_leaf] = second_tree->root;
  11. first_tree->temporary = true;
  12. second_tree->temporary = true; //czy trzeba?
  13. return (*first_tree);
  14. }
  15. else{
  16. delete first_tree;
  17. second_tree->temporary = true;
  18. return *second_tree;
  19. }
  20. }
  21. else{
  22. second_tree->temporary = true;
  23. return *second_tree;
  24. }
  25. }
  26.  
  27. Tree& Tree::operator=(Tree& other_tree){
  28. Node* copied_root = new Node(*other_tree.root);
  29. arguments.clear();
  30. errors.clear();
  31. if (root != NULL) {
  32. delete root;
  33. root = copied_root;
  34. }
  35. for (int i=0; i<other_tree.arguments.size(); i++){
  36. arguments.push_back(other_tree.arguments[i]);
  37. }
  38. for (int i=0; i<other_tree.errors.size(); i++){
  39. errors.push_back(other_tree.errors[i]);
  40. }
  41. if (other_tree.temporary) {
  42. delete &other_tree;
  43. }
  44. return (*this);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement