Skip to content

Instantly share code, notes, and snippets.

@alexeytal
Last active January 27, 2016 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexeytal/e65a97cd2669874f790b to your computer and use it in GitHub Desktop.
Save alexeytal/e65a97cd2669874f790b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printArray(int b[], unsigned size)
{
for (int i=0; i < size; i++)
cout<< b[i] << ' ';
cout << endl;
}
void swapTwoElements (int digits[], int index1, int index2) {
int temp = 0;
temp = digits[index1];
digits[index1] = digits[index2];
digits[index2] = temp;
}
void permutation(int a[], unsigned size, int shift)
{
for (int 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