Original Post
Hey, Im creating an array of lists. I need to be able to iterate through the list for printing and comparison reasons. This code is not completely done by any means so the code I'll be posting is very rough. I'm just getting an error that is saying: "expression must have class type". Im getting this error where im creating my for loop for the iterator. If anyone has any suggestions let me know. Thanks!
#include "LinkingHash.h"
int LinkingHash::getHash( string str )
{
int result = 0;
for ( unsigned int i = 0; i < str.length(); i++ )
{
result = result + ( int( str ) );
}
return result % 13;
}
void LinkingHash::addToHash( string str )
{
hashIndex = getHash( str );
hashTable[hashIndex].push_back( str );
//cout << hashTable[hashIndex].back() << endl;
list<string>::const_iterator it;
for( it = hashTable.begin();
it != hashTable.end();
it++)
{
}
}
void LinkingHash::deleteFromHash( string str )
{
hashIndex = getHash( str );
vector<string> vec;
for( unsigned int i = 0; i < hashTable[hashIndex].size(); i++ )
{
string temp = hashTable[hashIndex].back();
hashTable[hashIndex].pop_back();
vec.push_back( temp );
if ( vec.back() == str )
{
vec.pop_back();
}
}
for( unsigned int i = 0; i < vec.size(); i++ )
{
string temp = vec.back();
vec.pop_back();
hashTable[hashIndex].push_back( temp );
}
}
void LinkingHash::printHashTable()
{
int index = 0;
vector<string> vec;
while( index < SIZE )
{
cout << index << ") ";
/*list<string>::const_iterator Iterator;
for(Iterator = hashTable.begin();
Iterator != hashTable.end();
Iterator++)*/
for( unsigned int i = 0; i < hashTable[index].size(); i++ )
{
string temp = hashTable[hashIndex].back();
hashTable[hashIndex].pop_back();
vec.push_back( temp );
}
for( unsigned int j = 0; j < vec.size(); j++ )
{
string temp = vec.back();
vec.pop_back();
cout << temp << " ";
hashTable[hashIndex].push_back( temp );
}
cout << endl;
index++;
}
}