// aa.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <list>
#include <deque>
#include <algorithm>
#include <iostream>
using namespace std;
list<char> sc;
deque<char> dc;
char * s = "ABCD";
int t=0;
int flag=1;
void prt(char c) { cout<<c<<" "; }
void dojob(int lv) {
if(!lv--) {
cout<<endl;
flag=0;
return;
}
for(int i=0; i<strlen(s); ++i)
{
if( find(sc.begin(),sc.end(),s[i])==sc.end() )
{
if (flag)
{
cout<<s[i]<<' ';
}else
{
for_each(sc.begin(),sc.end(),prt);
flag=1;
cout<<s[i]<<' ';
}
sc.push_back(s[i]);
dojob(lv);
sc.pop_back();
}
}
}
void main() {
dojob(strlen(s));
cout << "total: " << t << endl;
}
帮你实现的。这个算法不代表我的实现,我会用2个自己写的链表实现