Exemplo n.º 1
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests PRUEFER_TO_TREE_2_NEW.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int NNODE = 9;

        int[] code = { 1, 3, 8, 8, 3, 6, 8, 0, 0 };

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  PRUEFER_TO_TREE_2_NEW produces a tree from its Pruefer code");

        typeMethods.i4vec_print(NNODE - 2, code, "  The Pruefer code:");

        int[] itree = Pruefer.pruefer_to_tree_2_new(NNODE, code);

        typeMethods.i4vec_print(NNODE - 1, itree, "  The edge list of the tree:");
    }
Exemplo n.º 2
0
    private static void test025()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST025 tests PRUEFER_TO_TREE_2.
    //
    //  Discussion:
    //
    //    This example is used to illustrate the Nijenhuis and Wilf algorithm
    //    LBLTRE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int NNODE = 4;

        int[] code  = new int[NNODE];
        int[] itree = new int[NNODE];
        int   j;

        Console.WriteLine("");
        Console.WriteLine("TEST025");
        Console.WriteLine("  PRUEFER_TO_TREE_2 produces a tree from its Pruefer code");
        Console.WriteLine("");
        Console.WriteLine("   Code      Tree");
        Console.WriteLine("");
        for (j = 1; j <= NNODE; j++)
        {
            code[1] = j;
            int i;
            for (i = 1; i <= NNODE; i++)
            {
                code[0] = i;
                Pruefer.pruefer_to_tree_2(NNODE, code, ref itree);
                Console.WriteLine("  " + code[0].ToString().PadLeft(2)
                                  + "  " + code[1].ToString().PadLeft(2)
                                  + "  "
                                  + "  " + itree[0].ToString().PadLeft(2)
                                  + "  " + itree[1].ToString().PadLeft(2)
                                  + "  " + itree[2].ToString().PadLeft(2) + "");
            }
        }
    }
Exemplo n.º 3
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests PRUEFER_TO_TREE_ARC.
    //
    //  Discussion:
    //
    //    The tree is
    //
    //          5
    //          |
    //    2-3-6-8-1-9
    //      |   |
    //      7   4
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]     code  = { 1, 3, 8, 8, 3, 6, 8 };
        const int nnode = 9;

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  PRUEFER_TO_TREE_ARC computes a tree from its Pruefer code.");
        Console.WriteLine("");
        Console.WriteLine("          5");
        Console.WriteLine("          |");
        Console.WriteLine("    2-3-6-8-1-9");
        Console.WriteLine("      |   |");
        Console.WriteLine("      7   4");

        typeMethods.i4vec_print(nnode - 2, code, "  The Pruefer code:");

        int[] inode = new int[nnode - 1];
        int[] jnode = new int[nnode - 1];

        Pruefer.pruefer_to_tree_arc(nnode, code, ref inode, ref jnode);

        Graph.graph_arc_print(nnode - 1, inode, jnode, "  The graph:");
    }