You shouldn't be checking for NULL
because you have an array of std::list
objects, not pointers.
You can check if the list at index i
has any elements with:
if (!hashTable[i].empty())
{
// there are elements in the list
}
Or
if (hashTable[i].size())
{
// there are elements in the list
}
Also in your print()
function, you're using an iterator of type std::list<int>
, but it should be std::list<string>
, which matches the declaration of hashTable
.