C# code. I'm a tester, so my code is a bit rusty, but the algorithm works.
public static void Permutations(string orgStr)
{
List permutations = new List();
_perm(orgStr.ToCharArray(), String.Empty, ref permutations);
foreach (string str in permutations)
{
Console.WriteLine(str);
}
}
private static void _perm(char[] sample, string filled, ref List permutations)
{
if (sample.Length == 1)
{
string perm = String.Format("{0}{1}", filled, new string(sample));
permutations.Add(perm);
}
else
{
for (int i = 0; i i)
{
newSample[j-1] = sample[j];
}
else
{
newSample[j] = sample[j];
}
}
_perm(newSample, newFilled, ref permutations);
}
}
}