Added just to help other....
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void createHashTable(void);
void getData(void);
void formatting(void);
int insertData(int);
int collision_OpenHashing(struct hashOpen*& ,int);
int generateKey(int);
void DispData(void);
void DispHash(void);
#define dataSize 15
#define empty -1
#define fail 0
#define success 1
struct hashOpen{
int item;
struct hashOpen *next;
}*head, hashTable[10];
int dataArray[dataSize];
struct hashOpen* cur;
int count, status;
int filledSpaces = 0;
float loadFactor = 0;
void main(void)
{
clrscr();
formatting();
getData();
createHashTable();
count = 0;
do
{
DispData();
DispHash();
printf("\ncount=%d", count);
status = insertData(dataArray[count]);
count++;
} while (count <= dataSize);
printf("\n\n-------------Programming Successfully Completed-------------");
getch();
}
void createHashTable(void)
{
int i;
/******** Initialize HashTable ************************/
for( i = 0; i <= 9; i++)
{
hashTable[i].item = empty;
hashTable[i].next = NULL;
}
}
void getData(void)
{
int i;
randomize();
for(i =0; i < dataSize; i++)
dataArray[i] = random(1)+2;
}
void DispData(void)
{
int i;
printf("\nData[]={");
for(i =0; i < dataSize; i++)
printf("%d,", dataArray[i]);
printf("\b}");
}
void DispHash(void)
{
int count;
printf("\nHash Table content = [");
for(count = 0; count < 9 ; count++)
{
printf("%d, ", hashTable[count].item);
cur++;
}
printf("\b\b]");
}
void formatting(void)
{
int i;
printf("\n");
for(i =0; i<=79 ; i++)
printf("*");
printf("\n......... Prgogram title\t\t# Hash Table");
printf("\n......... Created by\t\t # Romasa Qasim");
printf("\n......... Description\t\t # Creation of Hash Table, generation of,");
printf("\t\t\t\t\t Key, Insertion, Searching and Deletion");
printf("\t\t\t\t\t of data in the Hash Table\n");
for( i =0; i<=79 ; i++)
printf("*");
}
int insertData(int data)
{
int hashIndex;
hashIndex = generateKey(data);
if( hashTable[hashIndex].item == empty)
{
hashTable[hashIndex].item = data;
return(success);
}
else
return(collision_OpenHashing(hashTable[hashIndex].next, data));
}
int collision_OpenHashing(struct hashOpen *&pNode, int data)
{
if(pNode == NULL)
{
head = (struct hashOpen*)malloc(sizeof(struct hashOpen));
head->item = data;
head->next = NULL;
pNode = head;
}
else
collision_OpenHashing(pNode->next, data);
}
int generateKey(int data)
{
int key;
key = data % 10;
return(key);
}