The provided assignment content is a Java program that tests the functionality of an IntList class, particularly its methods for removing nodes based on a specific condition and sorting those nodes in place.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
import java.util.*; public class IntListMethodsTest { // Compute a simple XOR checksum of the indices of the nodes hanging from n. private static long checksum(int n) { int check = 0; while(n != 0) { check = check ^ n; n = IntList.getNext(n); } return check; } // Run the test and returnthe measured total running time. public static int test(intseed, int rounds, int size, boolean verbose) { int[] data = new int[size]; Random rng = new Random(seed); IntList.initialize(size + 5); int totalTime = 0; long startTime, endTime; for(int i = 0; i < rounds; i++) { for(int j = 0; j <size; j++) { data[j] = rng.nextInt(2 * size + 1) - size; } int lock = rng.nextInt(); int k = rng.nextInt(6) + 2; int n = IntList.allocate(data); if(verbose) { System.out.println("Original: " + IntList.toString(n)); } startTime = System.currentTimeMillis(); n = IntListMethods.removeIfDivisible(n, k); endTime = System.currentTimeMillis(); totalTime += (int)(endTime - startTime); if(verbose) { System.out.println("After removeIf(" + k + "): " + IntList.toString(n)); } int m = n, idx = 0; while(m != 0) { while(data[idx] % k == 0) { idx++; } if(IntList.getKey(m) != data[idx]) { System.out.println("ERROR: removeIf " + IntList.getKey(m) + " " + data[idx] ); return 9999999; } idx++; m = IntList.getNext(m); } Arrays.sort(data); long check1 = checksum(n); IntList.lockKeys(lock); startTime = System.currentTimeMillis(); n = IntListMethods.sort(n); endTime = System.currentTimeMillis(); totalTime += (int)(endTime - startTime); IntList.unlockKeys(lock);
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.