I have created a function to flip a square 2d array horizontally, so the first row is moved to the last, the second row is moved to the second from the last and so on.
Here is the function:
void flipMatrix(int size, int matrix[ROWS][COLS]) {
int row, col;
int temp[ROWS][COLS];
for (row=0; row < size; row++) {
for (col=0; col < size; col++) {
temp[(size - 1)-row][col] = matrix[row][col];
}
}
//A simple function that copies the temp array to matrix, so that
//I can then print the matrix array
copyArray(size, matrix, temp);
}
I know that this is very inefficient, but I am pretty new to C++. I was wondering how I would adapt this to be more efficient, maybe by returning a pointer? I'm also wondering if there is a way to do this without creating a temporary array?
I should also note, I am trying to do this without using the STL.
Thanks for the help.