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);
}
}
}
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());
}
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());
}
}
}
}
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);
}
}
}
}
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();
}
}
Aggregations