public override void Example() { Combination c = new Combination(5, 3); while (c != null) { Console.WriteLine(c.ToString()); c = c.Successor(); } Console.WriteLine(); string[] items = new string[] { "ant", "bug", "cat", "dog", "elk" }; c = new Combination(items.Length, 3); // 5개중 3개 조합 string[] snapshot = null; while (c != null) { snapshot = c.ApplyTo(items); Console.Write("{ "); foreach (string s in snapshot) { Console.Write(s + " "); } Console.WriteLine("}"); c = c.Successor(); } Console.WriteLine(); string[] items2 = new string[] { "apple", "banana", "cherry" }; Permutation p = new Permutation(items2.Length); while (p != null) { snapshot = p.ApplyTo(items2); Console.Write("{ "); foreach (string s in snapshot) { Console.Write(s + " "); } Console.WriteLine("}"); p = p.Successor(); } }
private void btnGenerateCombinations_Click(object sender, System.EventArgs e) { lbCombinations.Items.Clear(); int n = txtCaseInputs.Lines.Length; int k = int.Parse(txtSubsetSize.Text); Combination c = new Combination(n, k); string[] result = new string[k]; while (c != null) { result = c.ApplyTo(txtCaseInputs.Lines); StringBuilder sb = new StringBuilder(); for (int i = 0; i < result.Length; ++i) { sb.AppendFormat("{0} {1}", result[i], " "); } lbCombinations.Items.Add(sb.ToString()); c = c.Successor(); } }