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:

  1. create 500-element integer array using random class’s nextint() method
  2. make copy of array , use parameter sort methods (array passed reference).
  3. measure execution time sort 500-element array using bubble, selection, insertion, quicksort, , mergesort
  4. create 5000000-element integer array using random class’s nextint() method.
  5. make copy of array , use parameter sort methods (array passed reference).
  6. measure execution time sort 5000000-element array using bubble, selection, insertion, quicksort, , mergesort.
  7. measure execution time sort sorted (in increasing order) 500-element array using bubble, selection, insertion, quicksort, , mergesort.
  8. measure execution time sort reverse sorted (in decreasing order) 500- element array using bubble, selection, insertion, quicksort, , mergesort.
  9. measure execution time sort sorted (in increasing order) 5000000-element array using bubble, selection, insertion, quicksort, , mergesort.
  10. measure execution time sort reverse sorted (in decreasing order) 5000000- element array using bubble, selection, insertion, quicksort, , mergesort.
  11. 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

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -