1. Senior Member
Join Date
Jun 2007
Posts
114
Rep Power
0

## 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:
Java Code:
`insertionSort(int[]n) in InsertionSort cannot be applied to (int,int)`
Java 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:

2. Senior Member
Join Date
Jun 2007
Posts
111
Rep Power
0

## RE: Insertion sort algorithm

The error is telling you that you can't pass the two int's to the method insertionSort().
Java Code:
`private void insertionSort(int[] n)`
You're passing two ints:
Java Code:
`insertionSort(0, A.length-1);`
Greetings

Eric

3. Member
Join Date
Jun 2007
Posts
91
Rep Power
0

## RE: Insertion sort algorithm

Maybe you meant this:
Java Code:
`insertionSort(new int[] {0, A.length-1});`
Greetings!

Daniel:o

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•