import java.util.*; import com.jake.*; /** * P5 * * Name: Student ID: */ public class DeduceTheMysteryDataStructure { private static final int NUM_DATA_STRUCTURES_TO_DEDUCE = 5; private static final String getCS12UserID () { final Map env = System.getenv(); return env.get("USER"); } public static void main (String[] args) { // You may want to hard-code cs12UserID to your CSE 12 user ID if you are developing on // a non-CSE-lab machine. final String cs12UserID = getCS12UserID(); // final String cs12UserID = "cs12vZZ"; // Hard-coded instead System.out.println("My userID is set to: " + cs12UserID); // Fetch the collections whose type you must deduce. // Note -- you are free to change the type parameter from Integer to whatever you want. In this // case, make sure to replace (over the next 4 lines of code) Integer with whatever class you prefer. // In addition, you'll need to pass the method getMysteryDataStructure a "sample" (an instance) of // the class you want the collection to store. @SuppressWarnings("unchecked") final Collection12[] mysteryDataStructures = (Collection12[]) new Collection12[NUM_DATA_STRUCTURES_TO_DEDUCE]; for (int i = 0; i < NUM_DATA_STRUCTURES_TO_DEDUCE; i++) { mysteryDataStructures[i] = MysteryDataStructure.getMysteryDataStructure(cs12UserID, i, new Integer(0)); } // Write your code here... final Random random = new Random(); final int N = 100; for (int i = 0; i < N; i++) { // Note -- you might also want to randomize the *data* you add. mysteryDataStructures[0].add(new Integer(i)); } final int elementToFind = random.nextInt(N); // This is an example of measuring an operation's time cost *without* averaging -- the times will vary wildly! // You really should average... final long start = ArtificialClock.getNumTicks(); final boolean result = mysteryDataStructures[0].contains(elementToFind); final long end = ArtificialClock.getNumTicks(); final long elapsed = end - start; System.out.println("N\tT (contains(o))"); System.out.println(N + "\t" + elapsed); } }