2020-10-30 22:43:00 +00:00
|
|
|
function reverse(a, from, to) {
|
|
|
|
--from;
|
|
|
|
while (++from < --to) {
|
|
|
|
var tmp = a[from];
|
|
|
|
a[from] = a[to];
|
|
|
|
a[to] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function rotate(a, from, to, k) {
|
|
|
|
var n = to - from;
|
|
|
|
k = (k % n + n) % n;
|
|
|
|
if (k > 0) {
|
|
|
|
reverse(a, from, from + k);
|
|
|
|
reverse(a, from + k, to);
|
|
|
|
reverse(a, from, to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 22:28:29 +00:00
|
|
|
export default {
|
|
|
|
rotate
|
|
|
|
};
|