From 77f79341098383abd59b96fc79dc580c9b9b9bcc Mon Sep 17 00:00:00 2001 From: Muneeb Khan <96231592+muneeb-i-khan@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:45:18 +0530 Subject: [PATCH] Added Juggling Algorithm --- .../CPlusPlus/Arrays/Juggling-Algorithm.cpp | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 algorithms/CPlusPlus/Arrays/Juggling-Algorithm.cpp 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<