diff --git a/algorithms/CPlusPlus/Arrays/Juggling-Algorithm.cpp b/algorithms/CPlusPlus/Arrays/Juggling-Algorithm.cpp new file mode 100644 index 00000000..d979a12d --- /dev/null +++ b/algorithms/CPlusPlus/Arrays/Juggling-Algorithm.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); +} +void ArrayRotate(int A[], int n, int k) { + int d = -1, i, temp, j; + for (i = 0; i < gcd(n, k); i++) { + j = i; + temp = A[i]; + while (1) { + d = (j + k) % n; + if (d == i) break; + A[j] = A[d]; + j = d; + } + A[j] = temp; + } +} +void displayArray(int A[], int n) { + int i; + for (i = 0; i < n; i++) + cout<