Creating Hash Table

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!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#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);
}
Nothing calls hashTable or hashfunction. main doesn't do anything.

I don't know what you've done.
Topic archived. No new replies allowed.