codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  problem with recurssion  vinaysamineni at 14:10 on Tuesday, April 25, 2006
 

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;
}

}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  jslider - paint track
•  Re: convert minutes into hours and minutes
•  File handle problem
•  Link Capture, help needed
•  Re: java app auto web update..
•  IE Only comeback
•  ` Error Code 64: Host not available ` - Error when accessing ASP Appln
•  Re: dynamic crystal report generation
•  Launch an app remotely through a website


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007