Search in sources :

Example 41 with In

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

the class Whitelist method main.

public static void main(String[] args) {
    int[] w = new In(args[0]).readAllInts();
    StaticSETofInts set = new StaticSETofInts(w);
    while (!StdIn.isEmpty()) {
        int key = StdIn.readInt();
        if (!set.contains(key)) {
            StdOut.println(key);
        }
    }
}
Also used : StdIn(edu.princeton.cs.algs4.StdIn) In(edu.princeton.cs.algs4.In)

Example 42 with In

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

the class LazyPrimMST method main.

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

Example 43 with In

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

the class FileIndex method main.

public static void main(String[] args) {
    ST<String, SET<File>> st = new ST<String, SET<File>>();
    for (String filename : args) {
        File file = new File(filename);
        In in = new In(file);
        while (!in.isEmpty()) {
            String word = in.readString();
            if (!st.contains(word)) {
                st.put(word, new SET<File>());
            }
            SET<File> set = st.get(word);
            set.add(file);
        }
    }
    while (!StdIn.isEmpty()) {
        String query = StdIn.readString();
        if (st.contains(query)) {
            for (File file : st.get(query)) {
                StdOut.println(" " + file.getName());
            }
        }
    }
}
Also used : ST(edu.princeton.cs.algs4.ST) SET(edu.princeton.cs.algs4.SET) StdIn(edu.princeton.cs.algs4.StdIn) In(edu.princeton.cs.algs4.In) File(java.io.File)

Example 44 with In

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

the class LookupIndex method main.

public static void main(String[] args) {
    In in = new In(args[0]);
    String sp = args[1];
    ST<String, Queue<String>> st = new ST<String, Queue<String>>();
    ST<String, Queue<String>> ts = new ST<String, Queue<String>>();
    while (in.hasNextLine()) {
        String[] a = in.readLine().split(sp);
        String key = a[0];
        for (int i = 1; i < a.length; i++) {
            String val = a[i];
            if (!st.contains(key)) {
                st.put(key, new Queue<String>());
            }
            if (!ts.contains(val)) {
                ts.put(val, new Queue<String>());
            }
            st.get(key).enqueue(val);
            ts.get(val).enqueue(key);
        }
    }
    while (!StdIn.isEmpty()) {
        String query = StdIn.readLine();
        if (st.contains(query)) {
            for (String s : st.get(query)) {
                StdOut.println(" " + s);
            }
        }
        if (ts.contains(query)) {
            for (String s : ts.get(query)) {
                StdOut.println(" " + s);
            }
        }
    }
}
Also used : ST(edu.princeton.cs.algs4.ST) StdIn(edu.princeton.cs.algs4.StdIn) In(edu.princeton.cs.algs4.In) Queue(com.jimmysun.algorithms.chapter1_3.Queue)

Example 45 with In

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

the class CC method main.

public static void main(String[] args) {
    Graph G = new Graph(new In(args[0]));
    CC cc = new CC(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)

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