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