Question: The book uses LinkedList for buckets. Replace LinkedList with AVLTree. Assume E is Comparable. Redefine MyHashSet as follows: public class MyHashSet> implements Collection { ...
The book uses LinkedList for buckets. Replace LinkedList with AVLTree. Assume E is Comparable. Redefine MyHashSet as follows:
public class MyHashSet> implements
Collection {
...
}
Test your program using the main method in Listing 27.5.
Data from Listing 27.5.
![1 publ1c class TestMy HashSet { publ1c static void main (String[] args)](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1620/1/2/6/50460912b285fa341620126502996.jpg)
1 publ1c class TestMy HashSet { publ1c static void main (String[] args) { /I Create a My HashSet java.util.Collection set = new My HashSet (): set.add("Sm1th"): set.add("Anderson"): set.add("Lewis"): set.add( "Cook"): 2 3 4 6 7 8 9 set.add("Smith"): 10 System.out.println("Elements in set: " + set): System.out.printin("Number of elements in set: " + set.size()): System.out.printn("Is Smith in set? " + set.contains ("Sm1th")): 11 12 13 14 set.remove ("Sm1th"): System.out.print ("Names 1n set in uppercase are "): for (String s: set) System.out.print(s. toUpperCase () + " "): 15 16 17 18 19 20 set.clear(): 21 System.out.println(" Elements in set: " + set): 22 23 }
Step by Step Solution
3.56 Rating (160 Votes )
There are 3 Steps involved in it
import javautil public class Exercise2715 public static void mainString args Create a MyHashSet javautilCollection set new MyHashSet setaddSmith setaddAnderson setaddLewis setaddCook setaddSmith Syste... View full answer
Get step-by-step solutions from verified subject matter experts
