Search in sources :

Example 46 with In

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

the class DepthFirstPaths method main.

public static void main(String[] args) {
    Graph G = new Graph(new In(args[0]));
    int s = Integer.parseInt(args[1]);
    DepthFirstPaths search = new DepthFirstPaths(G, s);
    for (int v = 0; v < G.V(); v++) {
        StdOut.print(s + " to " + v + ": ");
        if (search.hasPathTo(v)) {
            for (int x : search.pathTo(v)) {
                if (x == s) {
                    StdOut.print(x);
                } else {
                    StdOut.print("-" + x);
                }
            }
        }
        StdOut.println();
    }
}
Also used : In(edu.princeton.cs.algs4.In)

Example 47 with In

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

the class AcyclicSP method main.

public static void main(String[] args) {
    EdgeWeightedDigraph G = new EdgeWeightedDigraph(new In(args[0]));
    int s = Integer.parseInt(args[1]);
    AcyclicSP sp = new AcyclicSP(G, s);
    for (int t = 0; t < G.V(); t++) {
        StdOut.print(s + " to " + t);
        StdOut.printf(" (%4.2f): ", sp.distTo(t));
        if (sp.hasPathTo(t)) {
            for (DirectedEdge e : sp.pathTo(t)) {
                StdOut.print(e + "   ");
            }
        }
        StdOut.println();
    }
}
Also used : In(edu.princeton.cs.algs4.In)

Example 48 with In

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

the class Euler method main.

public static void main(String[] args) {
    Digraph G = new Digraph(new In(args[0]));
    Euler euler = new Euler(G);
    if (euler.hasCycle()) {
        for (int v : euler.cycle()) {
            System.out.print(v + " ");
        }
        System.out.println();
    } else {
        System.out.println("Not has Eular cycle");
    }
}
Also used : In(edu.princeton.cs.algs4.In)

Example 49 with In

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

the class BoruvkaMST method main.

public static void main(String[] args) {
    In in = new In(args[0]);
    EdgeWeightedGraph G = new EdgeWeightedGraph(in);
    BoruvkaMST mst = new BoruvkaMST(G);
    for (Edge e : mst.edges()) {
        StdOut.println(e);
    }
    StdOut.println(mst.weight());
}
Also used : In(edu.princeton.cs.algs4.In)

Example 50 with In

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

the class WhiteFilter method main.

public static void main(String[] args) {
    SET<String> set = new SET<String>();
    In in = new In(args[0]);
    while (!in.isEmpty()) {
        set.add(in.readString());
    }
    while (!StdIn.isEmpty()) {
        String word = StdIn.readString();
        if (set.contains(word)) {
            StdOut.print(word + " ");
        }
    }
}
Also used : SET(edu.princeton.cs.algs4.SET) StdIn(edu.princeton.cs.algs4.StdIn) 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