Page 1 of 1

Desperately need help finishing this. Java program should randomly generate data to pass to the sorting methods. The pur

Posted: Sun Jul 03, 2022 11:24 am
by answerhappygod
Desperately need help finishing this. Java program shouldrandomly generate data to pass to the sorting methods. Thepurpose is to write the code to perform the benchmarking of thealgorithm using insertion sort. The program must include aniterative and a recursive version. In case the array is not sorted,an exception should be thrown using NotSortedException.
Code I have so far:
import java.util.Arrays;import java.util.Collection;import java.util.HashSet;import java.util.List;import java.util.LinkedList;import java.util.Random;import java.util.Set;
public class InsertRandomElements
{
public static void main(String[] args)
{
Random r = new Random(); int[] random = new int[50];
for (int i = 0; i <random.length; i++){ random =r.nextInt(100) + 1; }
for (int i = 0; i <random.length; i++){ System.out.println(random); }
List<int[]> randomList =Arrays.asList(random)
sortElements(randomList);
}
private static voidsortElements(Collection<int[]> values)
{
Set<int[]> set = newHashSet<int[]>(values);
for (int[] is : set) { System.out.printf("SortedElements: %d ", values); }
System.out.println(); }
}