when you stop allocating new arrays in the for loop, here you can make the newMatch = oldoldMatch , newInsert = oldoldInsert, newDelete = oldoldDelete. This way you rotate the already allocated arrays.