/**
  * *************************************************************************** Test client
  * ***************************************************************************
  */
 public static void main(String[] args) {
   BinarySearchST<String, Integer> st = new BinarySearchST<String, Integer>();
   for (int i = 0; !StdIn.isEmpty(); i++) {
     String key = StdIn.readString();
     st.put(key, i);
   }
   for (String s : st.keys()) StdOut.println(s + " " + st.get(s));
 }
Ejemplo n.º 2
0
  /** Unit tests the <tt>DirectedDFS</tt> data type. */
  public static void main(String[] args) {

    // read in digraph from command-line argument
    In in = new In(args[0]);
    Digraph G = new Digraph(in);

    // read in sources from command-line arguments
    Bag<Integer> sources = new Bag<Integer>();
    for (int i = 1; i < args.length; i++) {
      int s = Integer.parseInt(args[i]);
      sources.add(s);
    }

    // multiple-source reachability
    DirectedDFS dfs = new DirectedDFS(G, sources);

    // print out vertices reachable from sources
    for (int v = 0; v < G.V(); v++) {
      if (dfs.marked(v)) StdOut.print(v + " ");
    }
    StdOut.println();
  }