Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         BinarySearchST<String, Integer> st = new BinarySearchST<String, Integer>();
  3.         Out out = new Out("out.txt");
  4.         Out stud = new Out("studA.txt");
  5.        
  6.         // compute frequency counts
  7.         while (!StdIn.isEmpty()) {
  8.             String key = StdIn.readString();
  9.             if (key.contains(":") || key.startsWith(";")) continue;
  10.             String[] parts = key.split(";");
  11.             String userid = parts[0];
  12.  
  13.             if (st.contains(userid)) {
  14.                 st.put(userid, st.get(userid) + 1);
  15.             }
  16.             else {
  17.                 st.put(userid, 1);
  18.             }
  19.         }
  20.         // find user's and their frequency(value)
  21.         for (String user : st.keys()) {
  22.             out.println(user + " " + st.get(user));
  23.         }
  24.         out.println("Student with smallest id :" +st.min());
  25.         out.println("Student with biggest id :" + st.max());
  26.        
  27.         // find a key with the highest frequency count
  28.         String max = "";
  29.         st.put(max, 0);
  30.         for (String word : st.keys()) {
  31.             if (st.get(word) > st.get(max))
  32.                 max = word;
  33.         }
  34.         out.println("Student with highest login frequency :" + max + " " + st.get(max));
  35.        
  36.         // find users from lo to hi
  37.         String lo = "dai16001";
  38.         String hi = "dai16032";
  39.         for(String users : st.keys(lo, hi)) {
  40.             stud.println(users + " " + st.get(users));
  41.         }
  42.        
  43.        
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement