I'm not quite sure what you're trying to do but is this it?
1 2 3 4 5 6 7 8
| int[] targetArray = new int[1000]; int stride = 7; int length = targetArray.length;
for (int i=0;i<length;i+=stride) { System.out.println(targetArray[i]); } |
I assume its more complicated than this but hopefully this will give a started place to explain it more.
Kev
hehe, i wish it was that simple...
I want to iterate over all the elements at most once. i.e. once an element has been processed it is effectively no longer part of the array and needs to be ignored.
my current algorithm does the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| stride=3
Step 1 input array: 1 2 3 4 5 6 7 temporary container: 1 2 3 4 5 6 7 output array:
Step 2 input array: 1 2 3 4 5 6 7 temporary container: 1 2 4 5 6 7 output array: 3
Step 3 input array: 1 2 3 4 5 6 7 temporary container: 1 2 4 5 7 output array: 3 6
Step 4 input array: 1 2 3 4 5 6 7 temporary container: 1 4 5 7 output array: 3 6 2
Step 5 input array: 1 2 3 4 5 6 7 temporary container: 1 4 5 output array: 3 6 2 7
Step 6 input array: 1 2 3 4 5 6 7 temporary container: 1 4 output array: 3 6 2 7 5
Step 7 input array: 1 2 3 4 5 6 7 temporary container: 4 output array: 3 6 2 7 5 1
Step 8 input array: 1 2 3 4 5 6 7 temporary container: output array: 3 6 2 7 5 1 4 |
I want to be able to get rid of the temporary containter and directly be able to determine the next index to be placed in the output array...