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)?
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 };
elseif( x < t->element )
insert( x, t->left );
elseif( t->element < x )
insert( x, t->right );
else
//this is where I need to call the merge function
balance( t );
}