Ok I know how to write the actuall hash function what I'm having trouble with is the techniqe to resolve the collision there is a way called Dynamic Hashing I'm having trouble on how to write it. I understand how it works I just don't know were to start . here is the srtucture of the HashTable
Code:
typedef struct {
int key ;
char FName[10]; //First Name //
char LName[10]; // Last name //
char Tel[7]; //telephone number //
char city[10] ;
} element ;
and I've decided to use the mid square hash function
Code:
int hash( element Civil )
{
unsigned int v , x , y , w ;
w = Civil.key * Civil.key ; // this squares the Civil Id //
y = w << 16 ; // this takes the three bits in the key
x = y >> 29 ; // which are in the middle //
printf("x = %d \n" , x);
return (x);
}
in the main program it's a normal input of data using scanf then calling the function
Code:
int main()
{
int i , size ; // size of the elements we want to enter //
element Civil ;
element hash_table[TABLE_SIZE];
// Inserting data //
printf("Enter number of records you want to read: ");
scanf("%d" , & size);
for ( i = 0 ; i < size ;i ++)
{
printf("Enter civil ID:\n");
scanf("%d" , &Civil.key);
printf("Enter first name:\n");
scanf("%s" , &Civil.FName);
printf("Enter Last name :\n");
scanf("%s" , &Civil.LName);
printf("Enter telephone # :");
scanf("%s" , &Civil.Tel);
printf("Enter City:");
scanf("%s" , & Civil.city);
Dynamic_insert( Civil , hash_table); // this is the function I //
// want to create //
}
return(0);
}
Any one got any ideas on what I should do next . Is it a good idea to strat making it look like a binary tree ???