void iterate_permutations(std::string pre, std::string word, void (*func)(std::string) )
{
using namespace std;
if (word.size() == 1)
func(pre+word);
else
{
for(unsigned int i=0; i<word.size(); ++i)
{
char c = word;
string n_word = word;
n_word.erase( n_word.begin() + i );
iterate_permutations(pre + c, n_word, func);
}
}
}
void iterate_permutations_random(std::string pre, std::string word, void (*func)(std::string) )
{
using namespace std;
if (word.size() == 1)
func(pre+word);
else
{
//generate random order to traverse in
int *order = new int[word.size()];
for(int i=0; i<(int)word.size(); ++i)
order = i;
for(int i=0; i<(int)word.size(); ++i)
{
int j = randu(1, i);
int order_i = order;
order = order[j];
order[j] = order_i;
}
for(unsigned int j=0; j<word.size(); ++j)
{
int i = order[j];
char c = word;
string n_word = word;
n_word.erase( n_word.begin() + i );
iterate_permutations_random(pre + c, n_word, func);
}
delete order;
}
}