include<iostream>

using namespace std;
int main()
{

int Partnumber[15] = {112,130,156,173,197,150,166,113,123,143,167,189,193,117,176};
int Quantitynumber[15] = {12,30,56,17,19,50,66,13,12,14,16,18,19,11,76};
int hashTable[19][2];
int collisions = 0;
int index = 0;

for(int i = 0; i<15;i++)
{
    index = (Partnumber[i] % 19);
    hashTable[index] = Partnumber[i];

    if (hashTable[index] != 0)
    {
        do{
        index++
    }while(hashTable[index]!=0)
    }
    if(index >= sizeOf(hashTable) )
    {
    index=0;
    }
    else
    {
        hashTable[index] = Partnumber[i];
    }
    }






return 0;

}

First of all I must say that I'm am a newbie to hashing and I have an assignment for class. I'm not going to type the whole problem out but I'm having a problem creating a hashing function and handling collisions. I tried to do linear probing in the above code but I can tell that it won't work. Can somebody tell me a more efficient way of doing this. Here's a link to the problem:

http://www.cramster.com/answers-feb-10/computer-science/rate-highly-write-program-hashing-algorithm-create-li_759780.aspx?rec=0

I'm not asking anybody to write this program for me, but i need some direction with this hashing and linear probing algorithm. Thanks :D

Note: I have a two dimensional array to hold the part number along with it's quantity in separate columns

Edit: Also a problem that I'm having is starting back to the beginning of the hashTable if the calculated index is 19. As you can see I'm in desperate need of some help

See Knuth, Volume 3, Sorting and Searching, Addison-Wesley Pub.

I tried to do linear probing in the above ...

Looking at the link you gave, it looks like they want you to use link-lists for the collisions because in the section were it talks about

b. when requested, analyze the efficiency of the hashingalgorithm for this set of data. the printout format is
percentage of Prime Area Filled: xx%
Average nodes in linked list: nn
Longest linked list nn

If linked-list above is a link-list and you use linear probing, you would be able to print out these values.

Should you use linear probing?

Thanks guys i got it done

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.