java - How to sort an array of random numbers -
i need create array of size 500, , data randomly distributed , i'm confused how sort array. can me, please?
the code random:
import java.util.random; public class sorttest { public static void main(string[] args) { // create instance of random class random number generation random random = new random (1l); // begin new scope { // create int array of 500 elements int[] dataarray = new int[500]; // populate array randomly generated values (int index = 0; index < 500; index++) dataarray[index] = random.nextint(); // end scope } } }
do need use arrays.sort(dataarray)? or arrays.sort(dataarray, collections.reverseorder())? heard said not primary class.
please help!!! thank you!!
here should steps:
- create 500-element integer array using random class’s nextint() method
- make copy of array , use parameter sort methods (array passed reference).
- measure execution time sort 500-element array using bubble, selection, insertion, quicksort, , mergesort
- create 5000000-element integer array using random class’s nextint() method.
- make copy of array , use parameter sort methods (array passed reference).
- measure execution time sort 5000000-element array using bubble, selection, insertion, quicksort, , mergesort.
- measure execution time sort sorted (in increasing order) 500-element array using bubble, selection, insertion, quicksort, , mergesort.
- measure execution time sort reverse sorted (in decreasing order) 500- element array using bubble, selection, insertion, quicksort, , mergesort.
- measure execution time sort sorted (in increasing order) 5000000-element array using bubble, selection, insertion, quicksort, , mergesort.
- measure execution time sort reverse sorted (in decreasing order) 5000000- element array using bubble, selection, insertion, quicksort, , mergesort.
- tabulate results , comment on sensitivity of 6 sorting algorithms on input data distribution
i'm confused strp 7 , 8, how can sort array distributed above. , should add in? used arrays.sort() result printed out not in increasing order.
if asking way sorted array of random numbers, here's simple solution using java 8 streams:
int[] randoms = random.ints(500).sorted().toarray();
Comments
Post a Comment