# Insertion sort algorithm

• 06-28-2007, 07:26 PM
Albert
Insertion sort algorithm
Hi can anyone help me with this insertion sort algorithm
Everytime I try to compile the program I get the following
error message:
Code:

`insertionSort(int[]n) in InsertionSort cannot be applied to (int,int)`
Code:

```import java.util.Random; public class InsertionSort { Random RandomGenerator; int maxLength; private int[] A; public InsertionSort() { RandomGenerator = new Random(); maxLength = 100; } public void InsertionSortFunction(int n) { A = new int[n]; for (int i=0; i<n; i++) { A[i] = RandomGenerator.nextInt(maxLength); } insertionSort(0, A.length-1); display(); } private void insertionSort(int[] n) { data = new int[a.length]; for(int i=0;i<a.length;i++) data[i] = a[i]; int in, out; int N = data.length; for (out = 1; out < N; out++) { int temp = data[out]; in = out; while (in > 0 && data[in - 1] >= temp) { data[in] = data[in - 1]; in--; } data[in] = temp; } } public void display() { System.out.println("The lenght of array entered to be sorted is:"+"" + A.length); System.out.print("**The numbers after sorting**: "); for(int j=0; j<A.length; j++) System.out.print(A[j] + " "); System.out.println(" "); } }```
Greetings.

Albert:rolleyes:
• 06-28-2007, 08:20 PM
Eric
RE: Insertion sort algorithm
The error is telling you that you can't pass the two int's to the method insertionSort().
Code:

`private void insertionSort(int[] n)`
You're passing two ints:
Code:

`insertionSort(0, A.length-1);`
Greetings

Eric
• 06-28-2007, 08:26 PM
Daniel
RE: Insertion sort algorithm
Maybe you meant this:
Code:

`insertionSort(new int[] {0, A.length-1});`
Greetings!

Daniel:o