Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion in Java
#8
Why do we have that boolean without ever using it? Nevermind, I can't read.

I think the first statement is rather redundant. We've just entered the while loop, there's no reason to check right now whether or not "hi" is truly larger than "lo", is there? I guess you could do it just to be consistent with the other while, it didn't really help clarify things for me when I read it though.

There is also no need to specify that "lo <= length", since hi is always less than or at most equal to length, and you've already forced lo < hi before even doing anything.
Code:
while (lo < hi) {
                        while (toSort[lo] <= pivot && lo <= length && hi > lo) // <--- right here
                                lo++;                                    
                        while (toSort[hi] > pivot && hi >= low && hi >= lo)
                                hi--;

Also, if it were me, I'd choose more distinguishable names,. leftIndex and low for example.
look in indexes on the left of the pivot point to find a value that doesn't belong there translates nicely into:
Code:
while (toSort[leftIndex] < pivotValue) {
   leftIndex++;
}

I haven't really done any collaborative coding, so I still don't have a good idea what criteria constitute readable codes. I do know, though, that I had trouble reading yours. Could just be my limited understanding regarding quickSort itself, so iunno.
Reply


Messages In This Thread
Recursion in Java - by Five Second Pose - 2011-05-03, 06:06 PM
Recursion in Java - by Hazzy - 2011-05-03, 06:07 PM
Recursion in Java - by Five Second Pose - 2011-05-03, 06:20 PM
Recursion in Java - by Fiel - 2011-05-03, 07:10 PM
Recursion in Java - by Cyadd - 2011-05-03, 07:50 PM
Recursion in Java - by Nikkey - 2011-05-03, 08:18 PM
Recursion in Java - by Five Second Pose - 2011-05-03, 08:34 PM
Recursion in Java - by Kalovale - 2011-05-03, 08:52 PM
Recursion in Java - by Five Second Pose - 2011-05-03, 11:10 PM
Recursion in Java - by Kalovale - 2011-05-03, 11:23 PM
Recursion in Java - by Stereo - 2011-05-04, 12:09 AM
Recursion in Java - by SaptaZapta - 2011-05-04, 01:19 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)