Ejemplo n.º 1
0
        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();
            }
        }