Emulating a 2-d array using 1-d array - GeeksforGeeks
How to convert a 2-d array of size (m x n) into 1-d array and how to store the element at position [i, j] of 2-d array in 1-d array? Clearly, the size of 1-d array is the number of elements in 2-d array i.e. (m x n). If the elements in the 2-d array are stored in row-major order. Then, the element at index [i, j] in 2-d array will be stored in 1-d array at index k as:
k = j + (i * total_no_of_columns_in_matrix)
If the elements in the 2-d array are stored in column-major order, the value of index k will be
k = i + (j * total_no_of_rows_in_matrix)
Read full article from Emulating a 2-d array using 1-d array - GeeksforGeeks
No comments:
Post a Comment