Results 1 to 3 of 3
Thread: Insertion sort algorithm
- 06-28-2007, 07:26 PM #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)
Greetings.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(" "); } }
Albert:rolleyes:
- 06-28-2007, 08:20 PM #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().
You're passing two ints:Java Code:private void insertionSort(int[] n)
GreetingsJava Code:insertionSort(0, A.length-1);
Eric
- 06-28-2007, 08:26 PM #3
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
Similar Threads
-
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM -
Insertion Sort in Java
By Java Tip in forum AlgorithmsReplies: 0Last Post: 04-15-2008, 07:41 PM -
Using PreparedStatement for insertion
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:30 AM -
database insertion
By abhiN in forum New To JavaReplies: 0Last Post: 01-17-2008, 07:24 AM -
Help with sort algorithm
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks