//
// main.cpp
// Array Rotation
//
// Created by Himanshu on 18/09/21.
//
#include <iostream>
using namespace std;
const int N = 5;
void printArray (int A[]) {
for (int i=0; i<N; i++) {
cout<<A[i]<<" ";
}
cout<<endl;
}
void RotateByOneElement(int A[]) {
int temp = A[0];
for(int i=0; i<N-1; i++) {
A[i] = A[i+1];
}
A[N-1] = temp;
}
void Rotate (int A[], int d) {
cout<<"Array:"<<endl;
printArray(A);
for (int i=1; i<=d; i++) {
RotateByOneElement(A);
cout<<"Array after "<<i<<" rotation:"<<endl;
printArray(A);
}
}
int main() {
int A[N] = {5, 2, 4, 6, 1};
int d = 4;
Rotate(A, d);
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBBcnJheSBSb3RhdGlvbgovLwovLyAgQ3JlYXRlZCBieSBIaW1hbnNodSBvbiAxOC8wOS8yMS4KLy8KCiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gNTsKCnZvaWQgcHJpbnRBcnJheSAoaW50IEFbXSkgewogICAgZm9yIChpbnQgaT0wOyBpPE47IGkrKykgewogICAgICAgIGNvdXQ8PEFbaV08PCIgIjsKICAgIH0KICAgIGNvdXQ8PGVuZGw7Cn0KCnZvaWQgUm90YXRlQnlPbmVFbGVtZW50KGludCBBW10pIHsKICAgIGludCB0ZW1wID0gQVswXTsKICAgIAogICAgZm9yKGludCBpPTA7IGk8Ti0xOyBpKyspIHsKICAgICAgICBBW2ldID0gQVtpKzFdOwogICAgfQogICAgQVtOLTFdID0gdGVtcDsKfQoKdm9pZCBSb3RhdGUgKGludCBBW10sIGludCBkKSB7CiAgICBjb3V0PDwiQXJyYXk6Ijw8ZW5kbDsKICAgIHByaW50QXJyYXkoQSk7CiAgICBmb3IgKGludCBpPTE7IGk8PWQ7IGkrKykgewogICAgICAgIFJvdGF0ZUJ5T25lRWxlbWVudChBKTsKICAgICAgICBjb3V0PDwiQXJyYXkgYWZ0ZXIgIjw8aTw8IiByb3RhdGlvbjoiPDxlbmRsOwogICAgICAgIHByaW50QXJyYXkoQSk7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW50IEFbTl0gPSB7NSwgMiwgNCwgNiwgMX07CiAgICBpbnQgZCA9IDQ7CiAgICBSb3RhdGUoQSwgZCk7CiAgICAKICAgIHJldHVybiAwOwp9Cg==