Hey guys,
Thank you for the many times you guys have helped me.
I've spent an hour or so on this.
The Hash value is being set to 0 regardless of what values are Moded;
As far as I can tell the rest of my code functions properly.
The way this function works is by:
1. Read in a string.
2. Convert string to ascii value.
3. Mod by key.
4. Insert into table(table is a array of linked lists).
1 2 3
// these are defined elsewhere
#define MAX 67;
Table[MAX];
In the display later on it shows all strings set to Table[0].
1 2 3 4 5 6 7 8 9 10 11 12 13 14
while (getline(fin,temp))
{
strToDigit = 0;
// add up all values of string
strToDigit += atoi(temp.c_str());
// hash = integervalueofstring % 67 (defined above)
hash = strToDigit % MAX;
position = 0;
while (table[hash].getNumItems() >= position)
{
position++;
}
table[hash].insert(temp,position);
}
atoi converts a string that has the form of an integer. It's not really a hash function. If the string contains letters or other non-numerical characters it will probably fail.