Yeah, you guys are probably right....
I guess to me, it didn't matter that there wasn't any memory allocated to word*, as strcpy would take care of that...
Here is word:
Code:
class Files
{
private:
vector<int> fileList;
char* word;
public:
void addFile(int);
char* getWord()
{ return word; }
void setWord(const char* w)
{ strcpy(word,w); }
void printFile();
};
void Word::resize()
{
int newSize, index;
list<Files> tempList;
Files tempFile;
for (int i = 0; primes[i] < table.size(); i++)
{
newSize = primes[i+1];
}
vector<list<Files> > newTable = table, newTable2(newSize);
table = newTable2;
for (i = 0; i < newTable.size(); i++)
{
tempList = table.back();
table.pop_back();
for (int j = 0; j < tempList.size(); j++)
{
tempFile = tempList.front();
tempList.pop_front();
index = hash(tempFile.getWord(), table.size());
table[index].push_front(tempFile);
}
}
return;
}
void Word::addWord(Files file, int fileNum)
{
int index = hash(file.getWord(), table.size());
list<Files>::iterator it;
for (it = table[index].begin(); it != table[index].end(); it++ )
{
if (it == table[index].end())
{
table[index].push_front(file);
}
else if (!strcmp(it->getWord(),file.getWord()))
{
it->addFile(fileNum);
}
}
}
void Word::print()
{
list<Files>::iterator it;
for (int i = 0; i < table.size(); i++)
{
cout << i << " ";
for(it = table[i].begin(); it != table[i].end(); i++)
{
it->printFile();
}
cout << endl;
}
}