Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hash function

Status
Not open for further replies.

gheidi

Technical User
Feb 1, 2004
2
0
0
NO
I would like to write a program In C that reads 12 or so names. I'd like to insert the names according to a hash function. The collisions is solved using the
chaining method as shown below. The hash function should use the name as the key and returns a number between 0 and 2. The hash function should use all the characters of the name in order to produce the hashing index.

Example: producing the index using the first and second character.
....
char name [10];
printf ( “ enter a name \n”);
scanf (“%s”, name );
verdi = name[0] + name[1];
position = verdi % 2;

Can anyone help me get started?
 
You seem to be on your way in terms of creating a hash function. Use a for loop to sum each char of the string instead of the first two (hint, use strlen())



--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top