Search in sources :

Example 6 with In

use of edu.princeton.cs.algs4.In in project algorithms-sedgewick-wayne by reneargento.

the class Exercise27_Animations_Prim method main.

public static void main(String[] args) {
    // String filePath = Constants.FILES_PATH + Constants.TINY_EWG_FILE;
    String filePath = Constants.FILES_PATH + Constants.MEDIUM_EWG_FILE;
    EdgeWeightedGraph edgeWeightedGraph = new EdgeWeightedGraph(new In(filePath));
    // new Exercise27_Animations_Prim().new PrimMSTAnimations(edgeWeightedGraph, -0.1, 1.1,
    // -0.1, 1.1, 0.04); // Use these dimensions for tinyEWG.txt
    new Exercise27_Animations_Prim().new PrimMSTAnimations(edgeWeightedGraph, -1, 1001, -1, 1001, 15);
}
Also used : In(edu.princeton.cs.algs4.In)

Example 7 with In

use of edu.princeton.cs.algs4.In in project algorithms-sedgewick-wayne by reneargento.

the class DirectedDFS method main.

public static void main(String[] args) {
    Digraph digraph = new Digraph(new In(args[0]));
    Bag<Integer> sources = new Bag<>();
    for (int i = 1; i < args.length; i++) {
        sources.add(Integer.parseInt(args[i]));
    }
    DirectedDFS reachable = new DirectedDFS(digraph, sources);
    for (int vertex = 0; vertex < digraph.vertices(); vertex++) {
        if (reachable.visited[vertex]) {
            StdOut.print(vertex + " ");
        }
    }
    StdOut.println();
}
Also used : In(edu.princeton.cs.algs4.In) Bag(chapter1.section3.Bag)

Example 8 with In

use of edu.princeton.cs.algs4.In in project algorithms-sedgewick-wayne by reneargento.

the class Exercise2 method main.

/**
 * File content:
 *     6
 *     5
 *     2 5 33
 *     3 2 14
 *     4 5 89
 *     4 5 86
 *     3 0 15
 */
public static void main(String[] args) {
    String filePath = Constants.FILES_PATH + Constants.EWD_FILE;
    EdgeWeightedDigraphWithInConstructor edgeWeightedDigraphWithInConstructor = new Exercise2().new EdgeWeightedDigraphWithInConstructor(new In(filePath));
    StdOut.println(edgeWeightedDigraphWithInConstructor);
    StdOut.println("Expected:\n" + "0: \n" + "1: \n" + "2: 2->5 33.00 \n" + "3: 3->0 15.00 3->2 14.00 \n" + "4: 4->5 86.00 4-5 89.00 \n" + "5: ");
}
Also used : In(edu.princeton.cs.algs4.In)

Example 9 with In

use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.

the class AcyclicLP method main.

public static void main(String[] args) {
    In in = new In(args[0]);
    int s = Integer.parseInt(args[1]);
    EdgeWeightedDigraph G = new EdgeWeightedDigraph(in);
    AcyclicLP lp = new AcyclicLP(G, s);
    for (int v = 0; v < G.V(); v++) {
        if (lp.hasPathTo(v)) {
            System.out.printf("%d to %d (%.2f)  ", s, v, lp.distTo(v));
            for (DirectedEdge e : lp.pathTo(v)) {
                System.out.print(e + "   ");
            }
            System.out.println();
        } else {
            System.out.printf("%d to %d         no path\n", s, v);
        }
    }
}
Also used : In(edu.princeton.cs.algs4.In)

Example 10 with In

use of edu.princeton.cs.algs4.In in project AlgorithmsSolutions by Allenskoo856.

the class TestSearch method main.

public static void main(String[] args) {
    Graph G = new Graph(new In(args[0]));
    int s = Integer.parseInt(args[1]);
    DepthFirstSearch search = new DepthFirstSearch(G, s);
    for (int v = 0; v < G.V(); v++) {
        if (search.marked(v)) {
            StdOut.print(v + " ");
        }
    }
    StdOut.println();
    if (search.count() != G.V()) {
        StdOut.print("NOT ");
    }
    StdOut.println("connected");
}
Also used : In(edu.princeton.cs.algs4.In)

Aggregations

In (edu.princeton.cs.algs4.In)71 StdIn (edu.princeton.cs.algs4.StdIn)10 HashSet (chapter3.section5.HashSet)5 ArrayList (java.util.ArrayList)5 SeparateChainingHashTable (chapter3.section4.SeparateChainingHashTable)4 ST (edu.princeton.cs.algs4.ST)4 Stopwatch (edu.princeton.cs.algs4.Stopwatch)4 Bag (com.jimmysun.algorithms.chapter1_3.Bag)3 Queue (edu.princeton.cs.algs4.Queue)3 SET (edu.princeton.cs.algs4.SET)3 RedBlackBST (chapter3.section3.RedBlackBST)2 Transaction (edu.princeton.cs.algs4.Transaction)2 Bag (chapter1.section3.Bag)1 Queue (chapter1.section3.Queue)1 Queue (com.jimmysun.algorithms.chapter1_3.Queue)1 Date (edu.princeton.cs.algs4.Date)1 Out (edu.princeton.cs.algs4.Out)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1