【发布时间】:2011-05-26 03:22:55
【问题描述】:
是否存在对整数循环数组执行左移的现有方法?
具体来说,给定一个包含 4 个项目 {1,2,3,4} 且移位量为 2 的数组,我想要一种将前两个字母移动到数组后面的方法,使其看起来像这样:{3,4,1,2}。
这个算法能将一个圆形数组移动一个吗?
algShiftByOne(Array)
{
temp=array[0];
i=1
while(i < Array.length - 1) // Loop from 1 up to array.length == last index
{
// If there is no exception i assume it copies value from
// initial array starting from 1 up to array.length
Array[i - 1] = Array[i];
i++;
}
Array[Array.length]=temp;
}
【问题讨论】:
-
很有可能。这就是计算机科学的未来。