Friday 15 June 2012

pointers - C++, manipulate 2d array -


I created a function to flip horizontally a square 2d array, so the first row was moved to the previous, second line Has been moved from second to last and so on.

Here's the function:

  Zero flip matrix (integer size, at matrix [ROWS] [COLS]) {int row, col; Int [ROWS] [COLS]; (Line = 0; line; lie; line; line ++) {for (col = 0; col & lt; shape; col ++) {temp [(size - 1) -row] [col] = matrix [Row] [col]; }} // A simple function that copies the temporary array for the matrix, so that // matrix array can be copied to the array (size, matrix, temp); }  

I know that this is very incompatible, but I am quite new to C ++. I was wondering how I would make it efficient, maybe an indicator would return? I am also thinking that this is a way to do without creating a temporary array?

I should also note that I am trying to do this without using STL.

Thanks for the help.

You can use and swap values ​​in the bus (for (int line = 0; row & lt; ROWS; ++ line) {For (col = 0; call and lieutenant; COLS / 2; ++ col) // half column, do not do that you do not return it {std :: Swap is defined in swap (matrix [ROWS - row - 1] [cola], matrix [row] [col]];}}}

if you actually have STL If you can not use, then enough head to implement swap

  template  zero swap (T & PA, T & PB) {T Temp = pA; PA = PB; PB = floating;}  

No comments:

Post a Comment