Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Generates permutations of combinations of elements
- #include <iostream>
- using namespace std;
- void perm(int a[],int k,int n)
- {
- if(k==n)
- {
- for(int i=1;i<=n;i++)
- cout<<a[i]<<" ";
- cout<<endl;
- }
- else
- {
- for(int i=k;i<=n;i++)
- {
- int t=a[k];
- a[k]=a[i];
- a[i]=t;
- perm(a,k+1,n);
- t=a[k];
- a[k]=a[i];
- a[i]=t;
- }
- }
- }
- int main()
- {
- int a[4]={0,1,2,3}; //use your own type and values
- perm(a,1,3); //k=1 always at start
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement