hey, i wrote a program to create a hash table using an array of numbers, but I do not know how to display the actual table on my screen. Does anyone know how to display my results? So far, I am able to print the numbers that I have in the array. Any help or advice is appreciated. Thanks!
main.cpp
#include <iostream>
#include <cstring>
using namespace std;
int hashfunction(char *, int);
void hashTable (int &, char * );
const int HTsize = 13;
int main()
{
int num[10] = {70, 32, 86, 14, 20, 7, 15, 10, 13, 5};
for (int i = 0; i < 10; i++)
{
cout<<num[i]<<" ";
}
cout<<endl;
system("PAUSE");
return 0;
}
void hashTable(int &index, char *num)
{
char *hashArray[HTsize]; // same as hashArray[][]
bool found = false;
for ( int i = 0; i < HTsize; i++)
{ // search for duplicate
if(strcmp(num,hashArray[i]) == 0) // check for same num
found = true;
if (found) // duplicate found
index = ( index + 1 ) % HTsize;
strcpy(hashArray[index],num); // locate num in hash with an index
}
}
int hashfunction (char *key, int keylength)
{
int sum = 0;
for (int i = 0; i < keylength; i++)
sum += static_cast<int>(key[i]);
return (sum % HTsize);
}