|
hello i am trying to generate the permutatios of a given set of numbers
i am using recursion to get the permutations i am supposed to move the largetst number to the start and terminate generating the permutation when the maximum number reaches the first position and i have to display the permutations generated in each call in the called environment
i am placing the code here the problem with it is it can display only the last permutation
i really appreciate if some one can help me
thanks in advance
public class Test{
public static int start=1;
static void main(){
int[] array=new int[10];
for(int i=0;i<10;i++)
array=i;
int comparions=0;
int count=0;
do{
System.out.print("\n");
for(int i=0;i<array.length;i++)
System.out.print(array+"\t");
}while(nextPermutation(array));
}
public static boolean nextPermutation(int[] a)
{
int maxindex=0;
for(int i=0;i<a.length;i++)
{
if(a[maxindex]<a)
maxindex=i;
}
if(maxindex==0)
return false;
else
{
int temp=a[maxindex];
a[maxindex]=a[maxindex-1];
a[maxindex-1]=temp;
nextPermutation(a);
return true;
}
}
|
|
|
|
|
|
|
// |