Results 1 to 3 of 3
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default 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. #2
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default 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. #3
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default RE: Insertion sort algorithm

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

    Daniel:o

Similar Threads

  1. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM
  2. Insertion Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 07:41 PM
  3. Using PreparedStatement for insertion
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:30 AM
  4. database insertion
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 01-17-2008, 07:24 AM
  5. Help with sort algorithm
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:09 AM

Posting Permissions

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