Пример #1
0
    public static void ksub_next2_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    KSUB_NEXT2_TEST tests KSUB_NEXT2.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 December 2006
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int K = 3;

        int[]     a = new int[K];
        const int n = 5;

        Console.WriteLine("");
        Console.WriteLine("KSUB_NEXT2_TEST");
        Console.WriteLine("  KSUB_NEXT2 generates the next K subset of an");
        Console.WriteLine("  N set by the revolving door method.");
        Console.WriteLine("");
        Console.WriteLine("Rank  Subset  Added  Removed");
        Console.WriteLine("");
        //
        //  KSUB_NEXT2 does not have a good way of stopping.
        //  We will save the starting subset, and stop when the
        //  new subset is the same as the starting one.
        //
        int i_in  = 0;
        int i_out = 0;
        int rank  = 0;

        typeMethods.i4vec_indicator1(K, ref a);

        for (;;)
        {
            rank += 1;
            string cout = rank.ToString().PadLeft(2) + "  ";
            int    i;
            for (i = 0; i < K; i++)
            {
                cout += a[i].ToString().PadLeft(2) + "  ";
            }

            cout += "   ";
            cout += i_in.ToString().PadLeft(2) + "  ";
            Console.WriteLine(cout + i_out.ToString().PadLeft(2) + "");

            Ksub.ksub_next2(n, K, ref a, ref i_in, ref i_out);

            bool more = false;

            for (i = 1; i <= K; i++)
            {
                if (a[i - 1] != i)
                {
                    more = true;
                }
            }

            if (!more)
            {
                break;
            }
        }
    }