有人可以解释为什么该算法适用于将 2D 数组迭代为 1D 数组吗?换句话说..一个循环?
const int Width = 6;
const int Height = 4;
int Array[Width][Height];
for (int I = 0; I < Width * Height; ++I)
{
Array[I % Width][I / Width] = I; //This line :S
}
for (int I = 0; I < Height; ++I)
{
for (int J = 0; J < Width; ++J)
{
std::cout<<Array[J][I]<<" ";
}
std::cout<<"\n";
}