现在已经停留在这几天了,我正在走出我的想法。本质上,我已经将二维数组数组(一个图像,我知道有更简单的方法来实现这一点,但我有明确的要求)转换为一维数组。我可以轻松地旋转二维数组。我在旋转数组的1D版本时遇到了麻烦,我认为这只是一行算法不正确。 我使用的阵列旋转的代码是:顺时针旋转2D转换1D阵列90度
cout << "\nTransfer from 2D to dynamic 1D array and print details\n\n";
myImage * p_myImage = new myImage[total];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int offset = width * y + x;
p_myImage[offset].pixel = array2D[y][x];
cout << p_myImage[offset].pixel << " ";
}
cout << "\n";
}
//new pointer to copy to
myImage * p_myImage2 = new myImage[total];
cout << "\nRotate Matrix through 1D array\n\n";
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
int offset = height * x + y;
//int offset = width * y + x ;
p_myImage2[offset].pixel = p_myImage[height-1+x].pixel;
cout << p_myImage2[offset].pixel << " ";
}
cout << "\n";
}
样品的输入和输出将是有益的。描述你认为是错误的(超出'我认为某条线是错误的'),或者你不了解会改善这个问题。 SO不是调试服务。 – Caleb