/// <summary> /// Given two strings, write a method to decide if one is a permutation of the other /// </summary> /// <param name="sStr1"></param> /// <param name="sStr2"></param> public static void CheckPermutationsMk1BruteForce(string sStr1, string sStr2) { if (sStr1 == null || sStr1.Length == 0 || sStr2 == null || sStr2.Length == 0) { Console.WriteLine("Empty string!"); return; } else if (sStr1.Length != sStr2.Length) { Console.WriteLine("String lengths don't match!"); return; } else { CAppPermutationGenerator gen = new CAppPermutationGenerator(); int n = sStr1.Length; gen.GeneratePermutations(n, ref sStr1, ""); if (gen.Permutations.Contains <string>(sStr2)) { Console.WriteLine("String {0} is permutation of {1}", sStr1, sStr2); } else { Console.WriteLine("String {0} is not permutation of {1}", sStr1, sStr2); } } }
public static void Check() { string sInput = "1234"; int n = sInput.Length; CAppPermutationGenerator gen = new CAppPermutationGenerator(); gen.GeneratePermutations(n, ref sInput, ""); int i = 1; foreach (string s in gen.Permutations) { Console.WriteLine("{1}, Permutation: {0}", s, i); i++; } }