Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- BinarySearchST<String, Integer> st = new BinarySearchST<String, Integer>();
- Out out = new Out("out.txt");
- Out stud = new Out("studA.txt");
- // compute frequency counts
- while (!StdIn.isEmpty()) {
- String key = StdIn.readString();
- if (key.contains(":") || key.startsWith(";")) continue;
- String[] parts = key.split(";");
- String userid = parts[0];
- if (st.contains(userid)) {
- st.put(userid, st.get(userid) + 1);
- }
- else {
- st.put(userid, 1);
- }
- }
- // find user's and their frequency(value)
- for (String user : st.keys()) {
- out.println(user + " " + st.get(user));
- }
- out.println("Student with smallest id :" +st.min());
- out.println("Student with biggest id :" + st.max());
- // find a key with the highest frequency count
- String max = "";
- st.put(max, 0);
- for (String word : st.keys()) {
- if (st.get(word) > st.get(max))
- max = word;
- }
- out.println("Student with highest login frequency :" + max + " " + st.get(max));
- // find users from lo to hi
- String lo = "dai16001";
- String hi = "dai16032";
- for(String users : st.keys(lo, hi)) {
- stud.println(users + " " + st.get(users));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement