//************************************** // // Name: An implementation of Hashing // // Description:The purpose of this progr // am is to insert numbers into an hash arr // ay dynamically. // // // Inputs:Size of hash table and numbers // to be inserted are the inputs // // Returns:Program prints hash table and // number of probes for each number in orde // r to insert it into hash table. (Average // probe number is also printed) // // // // // // // // ************************************** // /* */ #include "stdio.h" #include "conio.h" #include "string.h" #include "ctype.h" #include "stdlib.h" // defining booleans #define true 1 #define false 0 // defining size of table, which is a pr // ime number #define Prime 11 //*************************** // Prototypes int HashIndex(int,int); int HashKey(int, int); void Initialization(void); void Presedence(void); void InsertKey(int,int); int ComputeNextPotentialAddress(int,int,int); int Try(int,int,int,int,int); void InsertAccordingTo(int, int, int, int, int); void WasteBrent(int); void PrintHashArray(int,int); int CalculateRetrieve(int,int); //*************************** // Global Variables int hash[15]; // hash table int pres[2][16]; // array for presedence int n;// size of table (required for hash and key functions) int needcheck=true; // a boolean //*********************************** // THIS FUNCTION PRINTS THE HASH ARRAY W // ITH NUMBER OF RETRIEVES void PrintHashArray(int usernumarray[],int numbercounter) { int totalprobe=0; int probe; int i; int counter=0; for(i=0;i=0){ index=(index+key)%n; if(index==storedindex) { printf("Table is Full"); getch(); exit(0); } if(hash[index]==num) { printf("Duplicate Record"); getch(); exit(0); } returnval++; } } return returnval; } // INSERTS THE num INTO index INDEX OF H // ASH TABLE // <%!--"NOT NECESSARY TO WRITE THIS // CODE BUT ..."--%> void InsertKey(int num, int index) { hash[index]=num; } // CALCULATES THE HASH INDEX OF NUMBER int HashIndex(int num,int prime){ // number and p prime number int returnval; returnval=num%prime; return returnval; } // CALCULATES THE INCREMENT KEY OF NUMBE // R int HashKey(int num, int prime){ // number and p prime number int returnval; returnval=((num/prime)%prime); return returnval; } // CALCULATE PRESEDENCE ARRAY FOR BRENTS // HASHING // 1-1, 1-2, 2-1, 1-3, 2-2, 3-1 ..... void Presedence(void){ int arrindex=0; for(int k=2; k<7; k++) for(int l=1; l