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)

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

1 Expert Approved Answer
Step: 1 Unlock

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

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 Introduction to Java Programming and Data Structure Questions!