字符全排列递归算法
public class Main {
private static char [] str = {'1','2','3','4'} ;
public static void main(String[] args) {
arrange(str.length);
}
private static void arrange(int size){
if (size == 1)
{
show();
return ;
}
for (int i= 0 ; i < size ; i ++)
{
arrange(size -1);
shift(size);
}
}
private static void show() {
for (char c:str)
System.out.print(c);
System.out.println();
}
/**
* 将str数组的后size位前移一个位置
*/
private static void shift(int size) {
char c = str[str.length - size];
for (int i=str.length - size + 1 ; i< str.length ; i ++)
{
str[i-1] = str[i];
}
str[str.length - 1] = c ;
}
}