Question: (b) Design the largeToSmall method that, when given a HashMap M, returns a LinkedHashSet of String values where the words are inserted into the

(b) Design the largeToSmall method that, when given a HashMap M, returns a LinkedHashSet of String valuesFor this question you will work with a LinkedList data structure and implement several static. Accordingly,

(b) Design the largeToSmall method that, when given a HashMap M, returns a LinkedHashSet of String values where the words are inserted into the set in order of decreasing count. Words that have the same count do not need to be inserted in any particular order. E.g., "is" may come before "world". You cannot sort M. Hint: create an array of size c (where c is the highest word count) where each element is a LinkedHashSet . For every element e in M, add e to the set at index M[i], where i is the count of e in M. Then, append these sets in reverse order according to their index. We provide some pseudocode below. largeToSmall (M): // M is M.size(). c = Get Highest Count Word in M array [0.. c-1] for i in [0.. c-1]: array [i] = new LinkedHashSet (); = for every key k in M: i M.get (k) array [i-1].add (k) = // Append all linkedhashsets in reverse order. return array [c-1] appended to array [c-2] appended to array [0] largeToSmall (wordCount (s)) -> ("world", "is", "the", "healthy", "hello", "it", "i", "certainly", "agree", "that", "1", "and", "not"} For this question you will work with a LinkedList data structure and implement several static. Accordingly, you cannot use any LinkedList methods except .get, .add, and .size. You also cannot use any external methods from Arrays, Collections, or any other helper class. (a) Design the addLast method that, when given a LinkedList / and an int v, returns a new LinkedList with the same elements plus v added to the end of 1. (b) Design the set method that, when given a LinkedList 1, an int v, and an index i, returns a new LinkedList with the same elements, except that the element at index i is, instead, the value v. If i is less than zero or exceeds the length of 1, return null. (c) Design the toArray method that, when given a LinkedList / of Integer, returns an array containing the values from 1. (d) Design the reverse method that, when given a LinkedList 1, returns a new LinkedList containing the elements of 1, but reversed.

Step by Step Solution

3.36 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here are the implementations of the methods youve requested a Design the addLast method ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!