This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes quick sort algorithm Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "quick sort algorithm" Watch "quick sort algorithm" New topic
Author

quick sort algorithm

Jeremy King
Greenhorn

Joined: May 27, 2008
Posts: 5
I have this problem to do and am having trouble with it. We were told that we should implement the following methods,
public static void sort(Comparable[] a, int begin, int end)
private static int split(Comparable[] a, int begin, int end)
I'm not quite sure where to start.


[edit]Added code tags. CR[/edit]
[ June 06, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
Welcome to JavaRanch.

Please use code tags (button below the message window); I have added them for you so you can see how much better quoted code looks.

You need to read about the Comparable interface. Declaring Comparable[] means that every type of your array implements the Comparable interface, and it therefore has a compareTo() method. If you pass an object of the appropriate type to compareTo, you get an int result which is negative if the first object is "less than" the other, or positive if it is "more than" or 0 if they are "the same." Do your programming in little bits, and see that it works before trying the next bit.

You are using String[] arrays; of course Strings implement the Comparable interface.

BTW: It's "the quick brown fox jumps over a lazy dog." But you can have two "the"s if you wish.

You can use that result ( < 0 or == 0 or > 0) to tell which pairs need to be swapped. If that proves awkward, start off with an int[] and use array[i] < array[j], then try array[i] - array[j] < 0, then you replace the int[] array with a Comparable[] array.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: quick sort algorithm
 
Similar Threads
I can NOT compile first class below
question about assertion
Array in reverse order......?
how to compile java source code with assertion ?
Clarification for quicksort