Search in sources :

Example 11 with In

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

the class KosarajuSCC method main.

public static void main(String[] args) {
    Digraph G = new Digraph(new In(args[0]));
    KosarajuSCC cc = new KosarajuSCC(G);
    int M = cc.count();
    StdOut.println(M + " components");
    Bag<Integer>[] components = (Bag<Integer>[]) new Bag[M];
    for (int i = 0; i < M; i++) {
        components[i] = new Bag<Integer>();
    }
    for (int v = 0; v < G.V(); v++) {
        components[cc.id(v)].add(v);
    }
    for (int i = 0; i < M; i++) {
        for (int v : components[i]) {
            StdOut.print(v + " ");
        }
        StdOut.println();
    }
}
Also used : In(edu.princeton.cs.algs4.In) Bag(com.jimmysun.algorithms.chapter1_3.Bag)

Example 12 with In

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

the class Ex15 method readInts.

public static int[] readInts(String name) {
    In in = new In(name);
    String input = in.readAll();
    String[] words = input.split("\\s+");
    int[] ints = new int[words.length];
    for (int i = 0; i < words.length; i++) {
        ints[i] = Integer.parseInt(words[i]);
    }
    return ints;
}
Also used : In(edu.princeton.cs.algs4.In)

Example 13 with In

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

the class FordFulkerson method main.

public static void main(String[] args) {
    FlowNetwork G = new FlowNetwork(new In(args[0]));
    int s = 0, t = G.V() - 1;
    FordFulkerson maxflow = new FordFulkerson(G, s, t);
    StdOut.println("Max flow from " + s + " to " + t);
    for (int v = 0; v < G.V(); v++) {
        for (FlowEdge e : G.adj(v)) {
            if ((v == e.from()) && e.flow() > 0) {
                StdOut.println("  " + e);
            }
        }
    }
    StdOut.println("Max flow value = " + maxflow.value());
}
Also used : In(edu.princeton.cs.algs4.In)

Example 14 with In

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

the class DirectedDFS method main.

public static void main(String[] args) {
    Digraph G = new Digraph(new In(args[0]));
    Bag<Integer> sources = new Bag<Integer>();
    for (int i = 1; i < args.length; i++) {
        sources.add(Integer.parseInt(args[i]));
    }
    DirectedDFS reachable = new DirectedDFS(G, sources);
    for (int v = 0; v < G.V(); v++) {
        if (reachable.marked(v)) {
            StdOut.print(v + " ");
        }
    }
    StdOut.println();
}
Also used : In(edu.princeton.cs.algs4.In) Bag(com.jimmysun.algorithms.chapter1_3.Bag)

Example 15 with In

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

the class KruskalMST method main.

public static void main(String[] args) {
    In in = new In(args[0]);
    EdgeWeightedGraph G = new EdgeWeightedGraph(in);
    KruskalMST mst = new KruskalMST(G);
    for (Edge e : mst.edges()) {
        StdOut.println(e);
    }
    StdOut.println(mst.weight());
}
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