# Help with sorting numbers

• October 5th, 2010, 03:55 AM
planktonx
Help with sorting numbers
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
Code :

```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

Code :

```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); } }```

• October 5th, 2010, 07:09 AM
aussiemcgr
Re: Help with sorting numbers
Is this for class and you have to make your own sort?

If not, you can simply say:
Code java:

`Arrays.sort(myArray);`
and your array will be sorted.
• October 5th, 2010, 08:01 AM
Norm
Re: Help with sorting numbers
Quote:

having trouble combining the two
Are you asking how to call a method in one class from a method in another class?

One way is shown in post#2. Define the method to be called as static.
The other way is to create an instance of the object and use that to call the method.