Getting some error in the code

        delete [] oldtable;

this statement should come outside loop
Modified Code