Resize the hash table and rehash every element I'm trying to increase my hash table size by two if the table is filled more than half of it. I tried to rehash every single element from the old table and put it back to my new table, then assign my old table as the new table again. What do you guys think of my own created function? I'm practicing for my final exam and only creating this in paper. I haven't tried yet using compiler and so forth.

I'm using quadratic probing to insert the keys, and once more than half of the table is filled, resize the hash table by calling the function resize().

//find index
int HashingTable::hash(int x, int size){
     return x % size;
}

//insert value to the array, but using quadratic probing
void HashingTable::insertQuadratic(int x, int T[]) {
    int index = hash(x, size);
    int i = 1;
    //the quadratic probing
    while (T[index] != empty) {
        index = (index + (i*i)) % size; //increment quadraticly
        i = i + 1;
    }
    T[index] = x;
    numOfItems = numOfItems + 1;
    double loadFactor = numOfItems / size;
    if (loadFactor &gt;= 0.5) {
        resize(T);
    }
}

void HashingTable::resize(int T[]) {
    int newSize = 2 * size;
    int* newTable = new int[newSize];
    for (int i = 0; i &lt; newSize; i++) {
        newTable[i] = empty;
    }
    for (int i = 0; i &lt; newSize; i++) {
        if (T[i] != empty) {
            int index = hash(T[i], newSize);
            int i = 1;
            while (newTable[index] != empty) {
                index = (index + (i*i)) % newSize;
            }
            newTable[index] = T[i];
        }
    }
    T = newTable;
    delete newTable;
}
Advice 1

for (int i = 0; i &lt; newSize; i++) {
    if (T[i] != empty) {


Did you intend to iterate only over size entries from T? If so, you need:

for (int i = 0; i &lt; size; i++) {
    if (T[i] != empty) {


Advice 2

T = newTable;
delete newTable;


You deallocate the actual new table array. Also, since you don't delete the table pointed to by T, you leak memory. I think your intention was to write:

delete[] T;
T = newTable;


Advice 3

T is not a good name for a hash table, since people can confuse it with a type parameter. Consider using something like storage_array, storage_table, table, or similar.