0

Hi all, i am trying to do a quadratic hashing but i am having some

difficulties probably because i am not in the right logic.using this

code:

```
#include <iostream>
using namespace std;
int find(int);
void insert(int);
const unsigned int size = 13;
int load = 0; // number of slots currently occupied
int A[size];
/**
*returns the array index where the integer key x is found.
* If x is not in the hash table, return -1
*/
int find(int searchKey)
{
int hash= searchKey % size; //hash formula
if(A[hash]== searchKey )
return hash;
else
return -1;
}
/**
* inserts the key x in the hash table if it is possible.
* It does not insert x if either (a) x is already in the hash table
* or (b) inserting x will make the hash table more than half full
*
*/
void insert(int newItem)// Please help not sure
{
int hashVal;
if(find(newItem)!= -1)// call to find index exist
{
hashVal = find(newItem);// know the position or hash
while(A[hashVal]!= NULL)// check if position is empty
{
hashVal = hashVal + (int)Math.pow(load,2);
//quadratically go to next cell
hashVal %= size;
A[hashVal]= newItem // insert new item at the position
load++; // keep count of insert
cout << newItem <<" is inserted to slot " << initPos << endl;
}
A[hashVal]= newItem // insert new item at the position
load++; // keep count of insert
cout << newItem <<" is inserted to slot " << initPos << endl;
}
cout << newItem <<" is not inserted to slot to avoid load limit " << endl;
else
if (++load > size/2)
{
need helP!!!!!!
}
}
```