April 29, 2011
public class FrequencyCount { public static void main(String[] args) { // read in the words as an array String s = StdIn.readAll(); // s = s.toLowerCase(); // s = s.replaceAll(“[\",!.:;?()']“, “”); String[] words = s.split(“\\s+”); // sort the words Merge.sort(words); // tabulate frequencies of each word Counter[] zipf = new Counter[words.length]; int M = 0; [...]
Read the full article →
April 29, 2011
public class Merge { public static void sort(Comparable[] a) { sort(a, 0, a.length); } // Sort a[lo, hi). public static void sort(Comparable[] a, int lo, int hi) { int N = hi – lo; // number of elements to sort // 0- or 1-element file, so we’re done if (N <= 1) return; // recursively [...]
Read the full article →