Depth prioritization (numbers are all sorted)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.