The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with recurssion

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
vinay samineni

Posts: 1
Nickname: samineni
Registered: Apr, 2006

problem with recurssion Posted: Apr 25, 2006 6:14 AM
Reply to this message Reply
Advertisement
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(nextPermutati on(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)
re turn false;
else
{
int temp=a[maxindex];
a[maxindex]=a[maxindex-1];
a[maxindex-1]=temp;
nextPermutatio n(a);

return true;
}

}

Topic: Please help with an academic research Previous Topic   Next Topic Topic: How to convert this application into Applet, Thanks!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use