我试图整数整数和整数整数,到目前为止我的成功很少。整数整数与整数的整数
我具有从0 18个整数对于欲洗牌
int[] chunks = {2, 3, 10, 3};
整数的阵列开始像0整数的每个组块的阵列,以17
array = new int[18];
for(int i = 0; i < 18; i++){
array[i] = i;
}
和阵列, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 当2的块数组的第一个元素被选中时,前2个数组的元素0和1被选中。 1移动到数组的末尾,然后0。
现在的顺序是2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,0,1
对于第二块数组的元素,它的值为3,所以选择2,3,4并放在0和1之上。
现在订单是5,6,7,8,9, 10,11,12,13,14,15,16,17,2,3,4,0,1
这一直持续到整数的阵列完全符合所有块
数组洗好的与大块充分洗牌是15,16,17,5,6,7,8,9,10,11,1 2,13,14,2,3,4,0,1
研究
我已经尝试了编程的方面,这至今已经与
for(int i = 0; i < chunks[0] i++) {
int first = array[0];
System.arraycopy(array, 1, array, 0, array.length-1);
array[array.length - 1] = first;
}
更新
这是我正在使用的代码现在我得到以下结果 10,11,12,13,14,15,3,4,5,6,7,8,9,1,1,1,1,1 ,而不是 15,16,17,5,6,7,8,9,10,11,12,13,14,2,3,4,0,1
int[] array2 = array.clone();
int temp = array2[0];
int chunkIndex = 0;
int count = 0;
int chunkCount = 0;
//Loops 4 times
for(int i = 0; i < chunks.length; i++) {
//Loops as many times for the chunk element
while(chunks[i] > count) {
for(int k = 1; k < array2.length; k++) {
//Move all the elements back
array2[k-1] = array2[k];
}
chunkIndex = array2.length-1 - chunkCount;
array2[chunkIndex] = temp;
temp = array2[0];
count++;
}
//Increment the limit
chunkCount += chunks[i];
//System.out.println(chunkCount);
}
任何帮助将不胜感激,如果你需要我澄清任何事情让我知道。
谢谢
如果您可以与我们分享您迄今尝试过的代码,可能会有帮助吗? –
即使是你的for循环中的语法错误,也不会编译,因为你想把一个'Array'分配给一个'int'的最后一行('array [']'是一个'int' ) –
是的你是对的,这是我的错。我的意思是放入第一个而不是数组 – user221