rotate method
Rotates array
to the right by n
positions in place. For example,
with n = 3, the array 1,2,3,4,5,6,7
is rotated to 5,6,7,1,2,3,4
.
Implementation
// NOTE: Time is O(n*array.length)! Can be slow for big arrays!
static void rotate(Float64List array, int n) {
for (int i = 0; i < n; i++) {
for (int j = array.length - 1; j > 0; j--) {
double temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
}