Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tree& Tree::operator+ (Tree& other_tree){
- Tree* first_tree = new Tree(*this);
- Tree* second_tree = new Tree(other_tree);
- if (first_tree->root != NULL){
- Node* parent_of_leaf = &(first_tree->findParentOfLeaf());
- if (!parent_of_leaf->isLeaf()){
- int number_of_child_leaf = parent_of_leaf->whichChildIsLeaf();
- delete parent_of_leaf->children[number_of_child_leaf];
- parent_of_leaf->children[number_of_child_leaf] = second_tree->root;
- first_tree->temporary = true;
- second_tree->temporary = true; //czy trzeba?
- return (*first_tree);
- }
- else{
- delete first_tree;
- second_tree->temporary = true;
- return *second_tree;
- }
- }
- else{
- second_tree->temporary = true;
- return *second_tree;
- }
- }
- Tree& Tree::operator=(Tree& other_tree){
- Node* copied_root = new Node(*other_tree.root);
- arguments.clear();
- errors.clear();
- if (root != NULL) {
- delete root;
- root = copied_root;
- }
- for (int i=0; i<other_tree.arguments.size(); i++){
- arguments.push_back(other_tree.arguments[i]);
- }
- for (int i=0; i<other_tree.errors.size(); i++){
- errors.push_back(other_tree.errors[i]);
- }
- if (other_tree.temporary) {
- delete &other_tree;
- }
- return (*this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement