Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void printArray(int arr[], int n){
- for(int i=0;i<n;i++){
- cout << arr[i] << " ";
- }
- cout << endl;
- return;
- }
- void swap(int *x, int *y){
- long int t;
- t=*x;
- *x=*y;
- *y=t;
- }
- void sort(int *a,int n){
- long int p=n-1,i;
- while (p>=0){
- for(i=0;i<=(p-1);++i){
- if (a[i]<=a[i+1])
- swap(&a[i],&a[i+1]);
- else
- continue;
- }
- p--;
- }
- }
- void permute(int *array,int i,int length){
- if(length == i){
- printArray(array,length);
- return;
- }
- int j = i;
- for(j=i;j<length;j++){
- swap(array+i,array+j);
- permute(array,i+1,length);
- swap(array+i,array+j);
- }
- return;
- }
- int main(){
- int arr[] = {1, 2, 3, 4, 5};
- int n = 5;
- permute(arr, 0, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement