use of com.jimmysun.algorithms.chapter1_3.Bag 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();
}
use of com.jimmysun.algorithms.chapter1_3.Bag 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();
}
}
use of com.jimmysun.algorithms.chapter1_3.Bag in project AlgorithmsSolutions by Allenskoo856.
the class NFA method recognizes.
public boolean recognizes(String txt) {
Bag<Integer> pc = new Bag<Integer>();
DirectedDFS dfs = new DirectedDFS(G, 0);
for (int v = 0; v < G.V(); v++) {
if (dfs.marked(v)) {
pc.add(v);
}
}
for (int i = 0; i < txt.length(); i++) {
Bag<Integer> match = new Bag<Integer>();
for (int v : pc) {
if (v < M) {
if (re[v] == txt.charAt(i) || re[v] == '.') {
match.add(v + 1);
}
}
}
pc = new Bag<Integer>();
dfs = new DirectedDFS(G, match);
for (int v = 0; v < G.V(); v++) {
if (dfs.marked(v)) {
pc.add(v);
}
}
}
for (int v : pc) {
if (v == M) {
return true;
}
}
return false;
}
use of com.jimmysun.algorithms.chapter1_3.Bag 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();
}
use of com.jimmysun.algorithms.chapter1_3.Bag in project useful-java-links by Vedenin.
the class ApacheSynchronizedBagTest method main.
public static void main(String[] args) {
// Parse text to separate words
String INPUT_TEXT = "Hello World! Hello All! Hi World!";
// Create Multiset
Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));
// Print count words
// print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
System.out.println(bag);
// Print all unique words
// print [Hi, Hello, World!, All!] - in random orders
System.out.println(bag.uniqueSet());
// Print count occurrences of words
// print 2
System.out.println("Hello = " + bag.getCount("Hello"));
// print 2
System.out.println("World = " + bag.getCount("World!"));
// print 1
System.out.println("All = " + bag.getCount("All!"));
// print 1
System.out.println("Hi = " + bag.getCount("Hi"));
// print 0
System.out.println("Empty = " + bag.getCount("Empty"));
// Print count all words
//print 6
System.out.println(bag.size());
// Print count unique words
//print 4
System.out.println(bag.uniqueSet().size());
}
Aggregations