Last active
January 27, 2016 12:53
-
-
Save alexeytal/e65a97cd2669874f790b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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