package charSort; import java.util.ArrayList; import java.util.List; /** * 几位的组合 * @author root * */ public class CharSort { static String ss = "abc"; static char[] st = new char[10]; public static void main(String[] args) { // TODO Auto-generated method stub sort(ss, 0, 0); } //所有2位的组合 public static void sort(String ss, int start, int depth){ if(depth>1){ st[start]=' '; System.out.println(st); return; } for(int i=start; i<ss.length(); i++){ st[depth] = ss.charAt(i); sort(ss, i+1, depth+1); } } }
ab
ac
bc
package dictionary_order; /** * 全排列 * @author root * */ public class FullPermutation { static String s = "abc"; public static void main(String[] args) { // TODO Auto-generated method stub change(0, s.toCharArray()); } public static void change(int k, char []data){ if(k==data.length-1){ print(data); return; } char temp; for(int i = k;i<data.length ;i++){ temp = data[k]; data[k] = data[i]; data[i] = temp; change(k+1, data); temp = data[k]; data[k] = data[i]; data[i] = temp; } } public static void print(char[] data){ for(int i=0; i<data.length; i++){ System.out.print(data[i]); } System.out.println(); } }
bac
bca
cba
cab