I am very new to C++ and I am working on creating a program using HashTables. This is for homework. This is the first time I am using and creating HashTables, so forgive me in advance as to I don't know entirely what I am doing. The main problem I am having right now is incorporating my remove() function. I can get the code to compile, but when I run test the program out, it crashes. The error that I am receiving is
list iterator is not decrementable
Here is my hashtable class as well as my remove() function. Also need to incorporate a print method.
the code crashes when it calls the pop.back(). how would i traverse through my member list? i know i would have to go through the vector, then go through the List, and find if key is there, but i cannot seem to translate that into code.
inlinevoid HTable::remove( const string &key)
{
vector<list<string>>::iterator it = List.begin() ;
bool found = false ; // stop looking when the key is found.
while ( !found && it != List.end() )
{
list<string>::iterator at ; // if the list isn't empty, search it.
if ( !it->empty() && (at=find(it->begin(), it->end(), key)) != it->end())
{
it->erase(at) ; // found it, now remove it.
found = true ;
}
else
++it ; // not found, check the next list.
}
}
This will need some modification if multiple copies of the same key are allowed and remove should remove all of them.