Implement merge function within AVLtree insert function

We are given the AVLtree implementation. We have to right our own class SQMAP which contains a merge function that is called from the insert function within the AVL class.
We are given a file to parse which contains enzymes and recognition sequences. Here is an example from the file:
CseI/'NNNNNNNNNNGCGTC//
CsiI/A'CCWGGT//
CspI/'NNNNNNNNNNGCGTC//

CseI and CspI contains the same recognition sequence so in the insert function we want to call the merge function so the node in the tree contains CseI and CspI along with the recognition sequence.

My question is how do I write the merge function? I tried just adding the two vectors but that did not work. Also, how would I call it from the insert function? would it just be x->merge(t)?

This is what my SQMAP class looks like.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 class SQMAP{
public:
//default big five
SQMAP() = default;
SQMAP(const SQMAP &rhs) = default;
SQMAP& operator=(const SQMAP &rhs) = default;
SQMAP(SQMAP &&rhs) = default;
SQMAP& operator=(SQMAP &&rhs) = default;

SQMAP(const string & recseq_, const string & enzyme_);

bool operator<(const SQMAP &rhs) const;

friend ostream& operator<<(ostream& output, const SQMAP& SQM){
}
void Merge(const SQMAP &other_sequence);

private:
    string rec_seq	;
    vector<string> enzyme;
}; 

Here is what the insert function looks like from the AVL tree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void insert( const Comparable & x )
    {
        insert( x, root );
    }
void insert( const Comparable & x, AvlNode * & t )
    {
        if( t == nullptr )
            t = new AvlNode{ x, nullptr, nullptr };
        else if( x < t->element )
            insert( x, t->left );
        else if( t->element < x )
            insert( x, t->right );
       else
          //this is where I need to call the merge function

        balance( t );
    }
Topic archived. No new replies allowed.