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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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(); }
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply