Skip to content

Instantly share code, notes, and snippets.

@cra
Forked from alexeytal/Rotate_array.cpp
Last active January 27, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cra/832ab524e0754989dbc0 to your computer and use it in GitHub Desktop.
Save cra/832ab524e0754989dbc0 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printArray(const int* const b, const unsigned size)
{
for (unsigned i = 0; i < size; i++)
cout<< b[i] << ' ';
cout << endl;
}
void swapTwoElements (int* const digits, const int index1, const int index2) {
int temp = digits[index1];
digits[index1] = digits[index2];
digits[index2] = temp;
}
void permutation(int* const a, const unsigned size, const int shift)
{
for (unsigned i = 1; i < size; i++){
swapTwoElements(a,i,i-1);
}
}
int main(){
int size=10;
int shift=4;
int a[]={1,2,3,4,5,6,7,8,9,10};
for (int i=0; i<shift%size;i++ )
permutation(a,size,shift);
printArray(a,size);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment