思想来源:http://blog.csdn.net/lxmky/article/details/7987643
src = {1 2 3 4 5 6}
des={1 4 2 5 3 6}
//代码
const int M = 2;
const int N=3;
void MySort::MatrixReverseTest()
{//待转换的二维矩阵
int a[] = {1,2,3,4,5,6};
int len = M*N;
MatrixReverse(a,len);
//输出转换后的数据
}
void MySort::MatrixReverse(int *p,int len)
{
//这里i取值为des的索引,从1-(len-2),因为转换中1与最后一个元素的值,转换前后值不变,因此可以
不参与转换
{
//根据i,获取des数组i处的值在原src数列中的位置
if(i<j)
{
CircleMove(p,i,j);
}
}
}
//src,des数组的索引转换函数
{
for(int i=0;i<M*N;i++)
{
if(pos==((i*M)%(M*N-1)))
{
break;
}
}
return i;
}
//循环移动
{
int tmp = p[start];
p[start] = p[end];
while(end>start+1)
{
p[end]=p[end-1];
end--;
}
p[end]=tmp;
}