I used get()
and getline()
to read the file then input to my map()
. Then insert from map class to AVLTree
and AVLNode
class. What should I do to fix the const string error and where the exactly problem is? Thank you for all your time and help. Here is the whole code.
https://github.com/RichardHung/AVL-BST-Tree.git
60 13 SequenceMap.cpp [Error] passing 'const std::basic_string' as 'this' argument of 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]' discards qualifiers [-fpermissive]
[Note] void std::basic_string<_CharT, _Traits, _Alloc>::push_back(_CharT) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
[Note] no known conversion for argument 1 from 'const std::basic_string' to 'char'
template <typename Comparable_1, typename Comparable_2>
class AvlNode
{
Comparable_1 element1; // sequence
vector<Comparable_2> element2; // enzy
AvlNode *left;
AvlNode *right;
int height;
bool exist;
AvlNode( const Comparable_1 & theElement1, const Comparable_2 & theElement2, AvlNode *lt, AvlNode *rt, int h = 0, bool ex = false):
element1( theElement1 ),element2( theElement2 ), left( lt ), right( rt ), height( h ), exist( ex ) { }
friend class AvlTree<Comparable_1, Comparable_2>;
};
template <typename Comparable_1, typename Comparable_2>
void AvlTree<Comparable_1, Comparable_2>::insert( const Comparable_1 & x, const Comparable_2 y, AvlNode<Comparable_1, Comparable_2> * & t )
{
if( t == NULL )
t = new AvlNode<Comparable_1, Comparable_2>( x, y, NULL, NULL, true );
else if( x < t->element1 )
{
insert( x, y, t->left );
if( height( t->left ) - height( t->right ) == 2 )
if( x < t->left->element1 )
rotateWithLeftChild( t );
else
doubleWithLeftChild( t );
}
else if( x > t->element1 )
{
insert( x, y, t->right );
if( height( t->right ) - height( t->left ) == 2 )
if( x < t->right->element1 )
rotateWithRightChild( t );
else
doubleWithRightChild( t );
}
else // ( x == t->element1 )
{
t->element2 = y ;
}
t->height = max( height( t->left ), height( t->right ) ) + 1;
}
template <typename Comparable_1, typename Comparable_2>
class SequenceMap
{
public:
Comparable_1 key;
Comparable_2 value;
AvlTree < Comparable_1, Comparable_2 > avl;
BinarySearchTree < Comparable_1, Comparable_2 > bst;
SequenceMap(){};
~SequenceMap();
}
template <typename Comparable_1, typename Comparable_2>
void SequenceMap<Comparable_1, Comparable_2>::AVLinsert( const Comparable_1 & str, const Comparable_2 & set )
{
if ( avl.isEmpty( ) )
{
key = str;
value = set;
avl.insert( key, value );
}
else // check the enzy is duplicated or not
{
for( int i=0; i<set.size( ); i++ )
{
if ( avl.findEnzyme( key, set ) ) // if cannot find the enzy in the node
{
merge( set );
avl.insert( key, value );
}
}
// if find the same enzy in the node, do nothing to avoid duplicated.
}
}
main.cpp
while ( ! fin.eof( ) )
{
if ( fin.peek( ) == '/' )
{
fin.get(); // skip "/" and move ptr to next sequence
while ( fin.peek() != '\n' )
{
getline(fin, sequence, '/');
cout << "enzyme: " << enzyme << endl;
cout << "sequence: " << sequence << endl;
map.insert(tree, sequence, enzyme);
sequence.clear();
fin.get(); // skip "/" and move ptr to next sequence
if(fin.peek() == '/')
fin.get();
}
fin.get();
enzyme.clear();
}
else // if( enz != '/' )
{
enzyme += fin.get( );
}
}