Exemple #1
0
    public static void Test(TextAsset txt)
    {
        Graph G = new Graph(txt);
        int   s = 0;
        //int s = Random.Range(0, int.Parse(txt.text.Split('\n')[0]));
        DepthFirstPaths dfs = new DepthFirstPaths(G, s);

        for (int v = 0; v < G.V(); v++)
        {
            if (dfs.hasPathTo(v))
            {
                string str = s + " to " + v + ":  ";

                foreach (int x in dfs.pathTo(v))
                {
                    if (x == s)
                    {
                        str += x;
                    }
                    else
                    {
                        str += ("-" + x);
                    }
                }
                print(str);
            }
            else
            {
                print(s + " to " + v + ":  not connected\n");
            }
        }
    }
Exemple #2
0
    /**/ public static void main(string[] strarr)
    {
        In              i               = new In(strarr[0]);
        Graph           graph           = new Graph(i);
        int             num             = Integer.parseInt(strarr[1]);
        DepthFirstPaths depthFirstPaths = new DepthFirstPaths(graph, num);

        for (int j = 0; j < graph.V(); j++)
        {
            if (depthFirstPaths.hasPathTo(j))
            {
                StdOut.printf("%d to %d:  ", new object[]
                {
                    Integer.valueOf(num),
                    Integer.valueOf(j)
                });
                Iterator iterator = depthFirstPaths.pathTo(j).iterator();
                while (iterator.hasNext())
                {
                    int num2 = ((Integer)iterator.next()).intValue();
                    if (num2 == num)
                    {
                        StdOut.print(num2);
                    }
                    else
                    {
                        StdOut.print(new StringBuilder().append("-").append(num2).toString());
                    }
                }
                StdOut.println();
            }
            else
            {
                StdOut.printf("%d to %d:  not connected\n", new object[]
                {
                    Integer.valueOf(num),
                    Integer.valueOf(j)
                });
            }
        }
    }