Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007, 09:26 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-28-2007, 10:20 PM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-28-2007, 10:26 PM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
RE: Insertion sort algorithm
Maybe you meant this:
Code:
insertionSort(new int[] {0, A.length-1});
Greetings!

Daniel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort a list using Bubble sort algorithm Java Tip Algorithms 3 04-29-2008 10:04 PM
Insertion Sort in Java Java Tip Algorithms 0 04-15-2008 09:41 PM
Using PreparedStatement for insertion Java Tip Java Tips 0 02-06-2008 11:30 AM
database insertion abhiN New To Java 0 01-17-2008 09:24 AM
Help with sort algorithm zoe New To Java 1 08-07-2007 08:09 AM


All times are GMT +3. The time now is 04:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org