public class Exercise8 { // rotate a by d elements to the left public static void rotateLeft(int[] a, int d) { int n = a.length; revert(a, 0, d); revert(a, d, n-d); revert(a, 0, n); } // revert a[p..p+n-1] public static void revert(int[] a, int p, int n) { int left = p; int right = p+n-1; while (left < right) { int t = a[left]; a[left] = a[right]; a[right] = t; left = left+1; right = right-1; } } }