package com.wg.pailie;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
//import java.lang.String;
//
//public class TestPaiLie {
//
// void print(String x) { //打印字符串
// System.out.print(x + " ");
// }
//
// void swap(String[] str,int i,int j) { //将字符串数组中的第i个字符串和第j个字符串交换
// if(i!=j)
// {
// String tmp = new String();
// tmp = str[i];
// str[i] = str[j];
// str[j] = tmp;
// }
// }
//
// void arrange(String[] str, int st, int len) { //递归实现str[st]到str[len-1]的全排列
//
// if(st==len-1) //如果从字符串数组的最后一个字符串开始全排列,则依次打印字符串数组。
// {
// for(int j=0; j<len; j++)
// {
// print(str[j]);
// }
// System.out.println();
// }
// else{ //否则,依次递归调用。
// for(int i=st; i<len; i++)
// {
// swap(str,st,i);
// arrange(str,st+1,len);
// swap(str,st,i);
// }
// }
// }
//
// public static void main(String[] args) {
// String str[] = {"a","b","c","d","e","f"}; //定义字符串数组
// TestPaiLie test = new TestPaiLie();
// test.arrange(str,0,6); //实现字符串数组str从str[0]到str[3的全排列。
// }
//}
//
public class TestPaiLie {
private Stack<String> st;
private int len;
public TestPaiLie(int len) {
st=new Stack<String>();
this.len=len;
}
public void arrange(String str[]){
if(st.size()==len) {
for (int i = 0; i < st.size(); i++) {
System.out.print(st.get(i)+" ");
}
System.out.println();
}
for (int i = 0; i < str.length; i++) {
st.push(str[i]);
String newStr[]=new String[str.length-1];
int k=0;
for(int j=0;j<str.length;j++){
if(j==i) continue;
newStr[k++]=str[j];
}
arrange(newStr);
st.pop();
}
}
public static void main(String[] args) {
String str[] = {"a","b","c"};
TestPaiLie test = new TestPaiLie(str.length);
test.arrange(str);
}
}