Skip to content

Instantly share code, notes, and snippets.

@gogsbread
Created January 2, 2013 23:29
Show Gist options
  • Save gogsbread/4439349 to your computer and use it in GitHub Desktop.
Save gogsbread/4439349 to your computer and use it in GitHub Desktop.
Calculater permutations of a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dotNetPlayGround
{
class Permutations
{
private static int[] permutationValue = new int[0];
private static int numberOfElements = default(int);
private int elementLevel = -1;
public static void Main()
{
Console.WriteLine(MakeCharArray("abc"));
}
public static char[] MakeCharArray(string InputString)
{
char[] charString = InputString.ToCharArray();
Array.Resize(ref permutationValue, charString.Length);
numberOfElements = charString.Length;
return charString;
}
public void CalcPermutation(int r)
{
elementLevel++;
permutationValue.SetValue(elementLevel, r);
if (elementLevel == numberOfElements)
{
//OutputPermutation(permutationValue);
}
else
{
for (int i = 0; i < numberOfElements; i++)
{
if (permutationValue[i] == 0)
{
CalcPermutation(i);
}
}
}
elementLevel--;
permutationValue.SetValue(0, r);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment