001package algs12; 002import stdlib.*; 003/* *********************************************************************** 004 * Compilation: javac Whitelist.java 005 * Execution: java Whitelist whitelist.txt < data.txt 006 * Dependencies: StaticSetOfInts.java In.java StdOut.java 007 * Data files: http://algs4.cs.princeton.edu/11model/tinyW.txt 008 * http://algs4.cs.princeton.edu/11model/tinyT.txt 009 * http://algs4.cs.princeton.edu/11model/largeW.txt 010 * http://algs4.cs.princeton.edu/11model/largeT.txt 011 * 012 * Whitelist filter. 013 * 014 * 015 * % java Whitelist tinyW.txt < tinyT.txt 016 * 50 017 * 99 018 * 13 019 * 020 * % java Whitelist largeW.txt < largeT.txt | more 021 * 499569 022 * 984875 023 * 295754 024 * 207807 025 * 140925 026 * 161828 027 * [367,966 total values] 028 * 029 *************************************************************************/ 030 031public class Whitelist { 032 public static void main(String[] args) { 033 args = new String[] { "data/tinyW.txt" }; 034 StdIn.fromFile ("data/tinyT.txt"); 035 036 int[] w = new In(args[0]).readAllInts(); 037 StaticSETofInts set = new StaticSETofInts(w); 038 039 // Read key, print if not in whitelist. 040 while (!StdIn.isEmpty()) { 041 int key = StdIn.readInt(); 042 if (!set.contains(key)) 043 StdOut.println(key); 044 } 045 } 046}