Divide-and-conquer method to realize the 1-n of numbers by dictionary order the full array of Java languages

Source: Internet
Author: User
The package division method; Import java.util.arrays;/* * The digital 1-n is fully arranged  by the dictionary order from small to large output * such as  1-3   * 123-a 213 231 312 321 */class generatep{private int n;  1-n all digits of the full array private final int maxn = 110;//can be arranged up to the length of the combination  1-100private Boolean [] hashtable;private int [] P;publi c Generatep (int n) {//TODO auto-generated constructor STUBTHIS.N = n;hashtable = new BOOLEAN[MAXN];p = new int [MAXN]; Arrays.fill (hashTable, false); Arrays.fill (p, 0);} public void Generatep (int index) {if (index = = n + 1) {for (int i = 1; I <= n; i++) {System.out.print (p[i]);} System.out.println (); return;} for (int x = 1; <= n; x + +) {if (hashtable[x] = = False) {P[index] = x; hashtable[x] = true;generatep (index + 1); hashtable[ X] = false;}}}} public class Main {public static void main (string[] args) {//TODO auto-generated method Stubgeneratep generatep = new Gen Eratep (3); Generatep.generatep (1);}}

  

Divide-and-conquer method to realize the 1-n of numbers by dictionary order the full array of Java languages

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.