[code]
#include<iostream>
#include<string>
using namespace std;
void permute( const string & str);
void permute( const string & str, int low, int high);
int main()
{
int number;
string str;
cin >> str;
cout << endl;
permute(str);
return 0;
}
void permute( const string & str)
{
permute(str,0,str.length());
}
void permute( const string & str, int low, int high)
{
// base case of the recursion
if(low==high || low>high) {
cout << str << endl;
return;
}
// fix the first character in its place, and permute the rest
string copy_str = str;
permute(copy_str, low+1, high);
for(int i=low+1 ; i<high ; i++) { // fix the (low+1)th char, permute rest
// if ith and lowth char are the same, no need to swap them and no need to call permute
if(str[low]!=str[i]) {
string copy_str = str;
char temp=copy_str[low];
copy_str[low]=copy_str[i];
copy_str[i] =temp;
permute(copy_str, low+1, high);
}
}
}
//What are these lines of code doing in this function?
string copy_str = str;
char temp=copy_str[low];
copy_str[low]=copy_str[i];
copy_str[i] =temp;
[CODE]