Lets say, I have a MxN arrays: int *b; and int **c; where
- values in
bare stored by columns (fromc) and I need to put values
fromctob - values in
bare stored by rows (fromc) and I need to put values
fromctob
I know that basicly I would do it like that:
j = index / N;
i = index - (j * M);
in order to convert a 1D index into a 2D co-ordinate but have a problem
how to implement those 2 cases, 1) and 2)?
Let W be the width of the 2D array, and H its height. Then assuming row-major layout, the 1D index ‘ix’ relates to the 2D-index [x,y] as such:
e.g.: