将一维数组的索引转换为二维数组 [英] converting the index of 1D array into 2D array
本文介绍了将一维数组的索引转换为二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将1D数组的索引转换为2D数组?我知道如何将2D数组转换为1D (i * row + j的大小)
.我想要相反的东西.
How can I convert the index of 1D array into 2D array? I know how to convert a 2D array into 1D (i*the size of row+j)
. I want the opposite of that.
推荐答案
您需要知道的是:2D数组应具有多少列:假设您有一个20列10行的数组(array [20,10]):
What you need to know is: How many columns should the 2D array have: Lets say you have an array of 20 columns and 10 rows (array[20,10]):
int index = 47;
int numberOfColumns = 20;
int column = index % numberOfColumns;
int row = index / numberOfColumns;
// column == 7
// row == 2
这篇关于将一维数组的索引转换为二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文