![]() |
|
#1
|
|||
|
|||
Quicksort and randomized hoare partitionHey,
I am trying to write a quick sort lab that uses a randomized Hoare partition function. It doesn't seem to be working correctly. On some data sets, it will sort them very quickly, on others it will loop for infinity. I am not entirely sure what I am doing wrong. I have went over the hoare partition pseudocode mulitple times, as well as traced through the numbers on paper. I've pretty much spent a good 6 hours today trying to make this work. I also can't find ANY use of a hoare parition on any quick sort code on the internet. Any help would be great. I feel I am missing 1 key thing (or I did a stupid mistake that I can't find since I have been staring at it for so long). Please look over my quicksort and hoare partition function and see if any problems can be found. THANKS! Note: This compiles and runs on linux. It *should* also work on windows. Note 2: I passed count for general debugging. I removed all of my debug statements so it looks like count is being passed for no reason. Note 3: I need to implement the better way of generating random numbers. CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Quicksort and randomized hoare partitionQuote:
I am a "bottom-up" kind of guy, so let's start with #3. Did you test your random number generator? Do you think it generates random number between its "low" and "high" arguments? I just broke it out into a separate program: CPP / C++ / C Code:
Here is a sample run from gcc: Quote:
What's wrong? In general, for non-negative integers n and m, the value of the expression n%m is an int from 0 to m-1. That's not what you need. If you already have pseudo code for quicksort and the kind of partition that you need, I am not sure why you need to search the web, unless you just want to see if your book or class notes is/are wrong.. Anyhow, I typed hoare random partition into a search engine and got a ***lot*** of hits --- some of which were, naturally, irrelevant. However, near the top of the hit list I found this "oldie-but-goodie": http://www.comsc.ucok.edu/~mcdaniel/mcdaniel/cam/vopf Regards, Dave |
|
#3
|
|||
|
|||
Re: Quicksort and randomized hoare partitionLOL Oh my god.
Man, I feel like an idiot now. I swear I tested that, but I guess I didn't. Thank you very much!! It sorts now and doesn't seem to infinity loop. Thank you! |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The