public static HashSet doHashSetSearchSmallestint numItems S

public static HashSet<Integer> doHashSetSearchSmallest(int numItems) {

       System.out.print(\"doHashSetSearchSmallest: \");

       HashSet<Integer> set = new HashSet<>();

       // TODO Write code that adds integers 0 through (numItems - 1)

       // to set.

       long startTime = getTimestamp();

       // TODO Write code that checks if 0

       // is a member of set.

       long endTime = getTimestamp();

       long totalTime = endTime - startTime;

       System.out.println(totalTime);

      

       return set;

   }

Solution

Code that adds integers 0 through (numitems - 1) to the list. I have added a loop for adding values to the list

    for(int i=0; i<numItems-1; i++){

       set.add(0);

   }

Then the entire program becomes

public static HashSet<Integer> doHashSetAdd(int numItems) {

   System.out.print(\"doHashSetAdd: \");

   HashSet<Integer> set = new HashSet<>();

   long startTime = getTimestamp();

   for(int i=0; i<numItems-1; i++){

       set.add(0);

   }

   long endTime = getTimestamp();

   long totalTime = endTime - startTime;

   System.out.println(totalTime);

return set;

   }

public static HashSet<Integer> doHashSetSearchSmallest(int numItems) { System.out.print(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site