how do i get the permutations recursively?

#include "stdafx.h"
#include<iostream>

using namespace std;
using namespace System;

int recurse(int a[],int flag)
{
if(flag==1)
return a[flag-1];
else
{
int *temp=new int[flag];
for(int i=1;i<flag;i++)
temp[i]=a[i-1];
a[flag-1]=recurse(temp,flag-1);
}
for(int i=0;i<flag;i++)
cout<<a[i];
cout<<endl;
}

int main(array<System::String ^> ^args)
{
int a[]={1,2};
recurse(a,2);
int j;
cin>>j;
}

My logic is like this:
first digit is kept same, then the next n digits are sent.those n digits are permuted and returned.this is repeated till all permutations are obtained.
Topic archived. No new replies allowed.