Hi All!
This is my code for generating the permutations for a number input,it takes an array of size n!*n where n is the input no., to find out the permutation.Please help me.
FOLLOWS MY CODE:#include<iostream>
void permute(int arr[],int pos);
int Factorial(int number);
int main(){
int num =0, fact = 0,SIZE=0 ;
cout<<"Enter the number to be Permuted: ";
cin>>num;
fact = Factorial(num);
SIZE = (fact*num);
int * Arr = new int [SIZE];
int pos =0;
permute(Arr,pos);
return 0;
}
void permute(int arr[],int pos){
int n,SIZE = 0;
int temp ,num;
SIZE = ((Factorial(num))*(num));
arr = new int [SIZE];
int *narr = new int [SIZE];
for (int i=0; i < SIZE ;i++)
narr[i] = arr[i];
if (pos >=SIZE -1)
{
for(int i=0; i<SIZE ;i++)
{
cout<<arr[i];
cout<<endl;
}
}
else
{
for (int next = pos; next < SIZE; next++)
{
temp = narr[next];cout<<temp;
narr[next] = narr[pos];cout<<narr[next];
narr[pos] = temp;
permute(narr, pos + 1);
}
}
}
int Factorial( int num)
{
int temp=0;
if(num <= 1) return 1;
else
temp = num * Factorial(num - 1);
return temp;
}
THANK U