Enter an integer n (n<10) and the full array of output 1-n
1 Importjava.util.Scanner;2 public classone {3 //array a (the box that simulates placing a digital card) is used to hold the sort number, array book[i] used to tag I have been put into the array a4 public Static inta[]=New int[10],book[]=New int[10],n;5 //the function f () is used to output the arrangement of all possible cases. 6 public Static voidFintx) {//x for the first few boxes7 if(x==n+1) {//When you play cards each time you put the sort output of the time8 for(intj=1;j<=n;j++){9System.out.print (a[j]+ "");Ten } oneSystem.out.println (""); a } - for(inti=1;i<=n;i++){ - if(book[i]==0) {//If the card I is still in hand thea[x]=i;//put the card I into the current box -book[i]=1;//tag I has been placed in the box (not on the Hand) -F (x+1);//go to the next box and keep Arranging. -book[i]=0;//Remove the card i, put a card in the box + } - } + } a public Static voidmain (String Args[]) { atScanner in=NewScanner (system.in); -n=In.nextint (); -F (1);//start placing cards from the first box - } -}
Digital Full Array
Depth prioritization (numbers are all sorted)