Exemplo n.º 1
0
  /** Unit tests the <tt>SET</tt> data type. */
  public static void main(String[] args) {
    SET<String> set = new SET<String>();

    // insert some keys
    set.add("www.cs.princeton.edu");
    set.add("www.cs.princeton.edu"); // overwrite old value
    set.add("www.princeton.edu");
    set.add("www.math.princeton.edu");
    set.add("www.yale.edu");
    set.add("www.amazon.com");
    set.add("www.simpsons.com");
    set.add("www.stanford.edu");
    set.add("www.google.com");
    set.add("www.ibm.com");
    set.add("www.apple.com");
    set.add("www.slashdot.com");
    set.add("www.whitehouse.gov");
    set.add("www.espn.com");
    set.add("www.snopes.com");
    set.add("www.movies.com");
    set.add("www.cnn.com");
    set.add("www.iitb.ac.in");

    StdOut.println(set.contains("www.cs.princeton.edu"));
    StdOut.println(!set.contains("www.harvardsucks.com"));
    StdOut.println(set.contains("www.simpsons.com"));
    StdOut.println();

    StdOut.println("ceiling(www.simpsonr.com) = " + set.ceiling("www.simpsonr.com"));
    StdOut.println("ceiling(www.simpsons.com) = " + set.ceiling("www.simpsons.com"));
    StdOut.println("ceiling(www.simpsont.com) = " + set.ceiling("www.simpsont.com"));
    StdOut.println("floor(www.simpsonr.com)   = " + set.floor("www.simpsonr.com"));
    StdOut.println("floor(www.simpsons.com)   = " + set.floor("www.simpsons.com"));
    StdOut.println("floor(www.simpsont.com)   = " + set.floor("www.simpsont.com"));
    StdOut.println();

    // print out all keys in this set in lexicographic order
    for (String s : set) {
      StdOut.println(s);
    }
  }
Exemplo n.º 2
0
  /** Unit tests the <tt>GraphGenerator</tt> library. */
  public static void main(String[] args) {
    int V = Integer.parseInt(args[0]);
    int E = Integer.parseInt(args[1]);
    int V1 = V / 2;
    int V2 = V - V1;

    StdOut.println("complete graph");
    StdOut.println(complete(V));
    StdOut.println();

    StdOut.println("simple");
    StdOut.println(simple(V, E));
    StdOut.println();

    StdOut.println("Erdos-Renyi");
    double p = (double) E / (V * (V - 1) / 2.0);
    StdOut.println(simple(V, p));
    StdOut.println();

    StdOut.println("complete bipartite");
    StdOut.println(completeBipartite(V1, V2));
    StdOut.println();

    StdOut.println("bipartite");
    StdOut.println(bipartite(V1, V2, E));
    StdOut.println();

    StdOut.println("Erdos Renyi bipartite");
    double q = (double) E / (V1 * V2);
    StdOut.println(bipartite(V1, V2, q));
    StdOut.println();

    StdOut.println("path");
    StdOut.println(path(V));
    StdOut.println();

    StdOut.println("cycle");
    StdOut.println(cycle(V));
    StdOut.println();

    StdOut.println("binary tree");
    StdOut.println(binaryTree(V));
    StdOut.println();

    StdOut.println("tree");
    StdOut.println(tree(V));
    StdOut.println();

    StdOut.println("4-regular");
    StdOut.println(regular(V, 4));
    StdOut.println();

    StdOut.println("star");
    StdOut.println(star(V));
    StdOut.println();

    StdOut.println("wheel");
    StdOut.println(wheel(V));
    StdOut.println();
  }
Exemplo n.º 3
0
 /** Unit tests the <tt>Digraph</tt> data type. */
 public static void main(String[] args) {
   In in = new In(args[0]);
   Digraph G = new Digraph(in);
   StdOut.println(G);
 }