PDA

View Full Version : java quicksort question



Runz W Scissorz
03-14-2005, 08:02 PM
hey im sorry if this isnt the appropriate place for this, but i dont know too many other reliable boards to ask on

i was wondering how the heck a quicksort is implemented with a randomly selected pivot. is this possible? im trying to implement one and I cant for the life of me get a correctly sorted list (keeping my left and right indexes from going out of bounds of the array was a challenge enough). im sure it is possible, ive just never seen it implemented, nor do i know why anyone would.

basically, id have an array of N integers, and id run

(private void) quicksortRandomPivot(int[] a, 0, N-1){
}

on them, where a is the array, 0 is the first or left index, and N-1 is the last or right index.

thanks if anyone knows how to implement one.

dvm
03-15-2005, 05:43 AM
You could try a book. Sedgewick's Algorithms in C++ is a classic I think. Then you'd only need to translate the code to java. That shouldn't be so hard.