#include
#include
#include
using namespace std;
int count = 0;
template
void Create(stack S, T tar[], T str[], int pos, int curp, int n)
{
if(pos < n) //还有元素没进栈则继续进栈
{
S.push(str[pos]); //进栈
Create(S, tar, str, pos+1, curp, n);
S.pop(); //出栈恢复环境
}
if(!S.empty()) //栈不为空则继续出栈
{
tar[curp] = S.top();//将出栈元素记录到目标数组中以待输出
S.pop(); //出栈
Create(S, tar, str, pos, curp+1, n);
S.push(tar[curp]); //进栈恢复环境
}
if(pos == n && S.empty()) //栈空且所有元素都进过栈则输出
{
tar[n] = '\0';
cout << "[" << ++count << "] " << tar << endl;
}
}
void main()
{
stack<char> S;
char str[6] = "ABCDE";
char tar[6];
Create(S, tar, str, 0, 0, 5);
ofstream outfile("myfile.txt",ios::out);
for(int i=0;i<count;i++)
{
outfile<< tar <<endl;
}
outfile.close();
cout<<"处理完毕,请打开文件查看结果!"<<endl;
}