public static HashSet doHashSetSearchGreatestint numItems S
public static HashSet<Integer> doHashSetSearchGreatest(int numItems) {
System.out.print(\"doHashSetSearchGreatest: \");
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 integer (numItems - 1)
// is a member of set.
long endTime = getTimestamp();
long totalTime = endTime - startTime;
System.out.println(totalTime);
return set;
}
Solution
1.Code that appends 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++)
list.add(i);
2.code that checks if integer (numItems - 1)
if(set.contains(numItems-1))
System.out.println((numItems-1)+ \" is a memeber of set\");
else
System.out.println((numItems-1)+ \" is not a memeber of set\");
long endTime = getTimestamp();
//long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println(totalTime);
