File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Need help figuring out a quickSort problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help figuring out a quickSort problem" Watch "Need help figuring out a quickSort problem" New topic

Need help figuring out a quickSort problem

Ryan Arment

Joined: Oct 03, 2011
Posts: 7
I am close to finishing this, but now I keep getting into an infinite loop. I am trying to debug but having no luck figuring out where my problem is. I am trying to do a standard quickSort and a quickSort using a stack. But I think the problem is with my partition method. It works on small arrays, up to like 20 but then it gets into an infinite loop. Any help would be greatly appreciated!

Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Look at line 12 in quickSortNonRec. There you state that do this as long as stack is not empty.

Then on line 22, 23 and 24, you push things onto the stack. When will it ever break out of the loop??

What is the end state??

Nevermind. I need to look into this a bit more...

Edit: What does the InsertionSorter.insertionSort(arr, start, end); //Sorts the array to the middle value on line 15 of partition do??
Don't get me started about those stupid light bulbs.
subject: Need help figuring out a quickSort problem
It's not a secret anymore!