-
-
Save cra/832ab524e0754989dbc0 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(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