/* 算法:输出数字串的全排列
*/
#include <iostream>
#include <list>
#include <string>
using namespace std;
//删除str的第n个字符
void DeleteCharAt(string& strSrc, int pos)
{
if (pos < 0 || pos >= strSrc.length())
{
return;
}
string tmpStr(strSrc.substr(pos + 1));
strSrc = strSrc.substr(0, pos) + tmpStr;
}
//递归函数
void RecurListAll(string& strBase, string strBuf, list<string>& retList)
{
if (strBase.length() <= 0)
{
retList.push_back(strBuf);
}
for(int i = 0; i < strBase.length(); i++)
{
string tmp(strBase);
DeleteCharAt(tmp, i);
RecurListAll(tmp, strBuf + strBase[i], retList);
}
}
int main(int argc, char* argv[])
{
string str = "123";
list<string> retList;
RecurListAll(str, "", retList);
//Here: retList --> ("123","132","213","231","312","321")
return 0;
}