Created
January 2, 2013 23:29
-
-
Save gogsbread/4439349 to your computer and use it in GitHub Desktop.
Calculater permutations of a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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