Hash table lookup Algorithm (hash) #include <stdio.h> #include <stdlib.h> #define OK 1 #define ERROR 0 #define TRUE 1 #def
INE FALSE 0 #define SUCCESS 1 #define UNSUCCESS 0 #define HASHSIZE 7 #define NULLKEY-32768 typedef int STATUS; typedef struct {int *elem; Base address int count;
The number of current data elements}hashtable; int m=0;
Hash table LONG/* Initialize */Status init (HashTable *hashtable) {int i;
M=hashsize; Hashtable->elem = (int *) malloc (M * sizeof (int));
Request Memory hashtable->count=m;
for (i=0;i<m;i++) {hashtable->elem[i]=nullkey;
return OK;
}/* Hash function (excluding remainder method) */int hash (int data) {return data% m;} /* Insert */void Insert (HashTable *hashtable,int data) {int hashaddress=hash (data);//hash address//conflict while (HASHTABL
E->elem[hashaddress]!=nullkey) {//Resolve conflict hashaddress= (++hashaddress)%m using open addressable linear detection;
}//Insert value hashtable->elem[hashaddress]=data; }/* Find */int search (HashTable *hashtable,iNT data) {int hashaddress=hash (data);//hash address//conflict while (Hashtable->elem[hashaddress]!=data) {
Solving conflict hashaddress= (++hashaddress)%m by using the open addressable linear detection method; if (hashtable->elem[hashaddress]==nullkey| |
Hashaddress==hash (data)) return-1;
//Find successful return hashaddress;
/* Print result/void Display (HashTable *hashtable) {int i;
printf ("\n//==============================//\n");
for (i=0;i