My goal is to generate 10,000 random numbers and sort them in arrays. I have the random numbers made easy enough and I have a small quick sort class but I am having trouble combining the two.
This is the random number generator
import java.util.*; public class NumberGenerator { public static void main(String args[]){ Random Generator = new Random(); int[] myArray = new int[10000]; for(int idx = 0;idx <=10000; ++idx){ int nums = Generator.nextInt(10000); myArray[idx] = nums; }
This is the quick sort
public class QuickSort { int partition(int array[], int left, int right) { int i = left, j = right; int tmp; int pivot = array[(left + right) / 2]; while (i <= j) { while (array[i] < pivot) i++; while (array[j] > pivot) j--; if (i <= j) { tmp = array[i]; array[i] = array[j]; array[j] = tmp; i++; j--; } }; return i; } void quickSort(int array[], int left, int right) { int index = partition(array, left, right); if (left < index - 1) quickSort(array, left, index - 1); if (index < right) quickSort(array, index, right); } }
Thanks for your help