![]() |
|
#1
|
|||
|
|||
Recursion and the confusion that comes with itHeh, well, here's my newest problem. We've been told to write a recursive method that will take a list of numbers, take the central (or a central) point, and sort them so that the left side is composed of nothing but numbers smaller than the pivot point, and the right side is nothing but numbers greater than the pivot point. Then it cuts the two sides up and repeats. We were given all of the other methods but qksortRecur and told to make it work, so I'm assuming everything else should remain untouched. I've written something I think SHOULD work... and couts before my attempts to call the method within the method work. Why am I getting nothing when I attempt to make the method call itself correctly? A cout at the top of the function shows me the function is at least calling itself fine, it prints out hundreds of times...
CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
Hi Elsydeon,
Your quicksorting fails in two aspects: 1. the recursion is endless -> runtime failure. 2. even if point 1 is fixed still fails to give correct answers.. Your implementation of your function qksortRecur() has following conceptual errors:
For the above reason I do not start to analyze your code. To write your recursive quick sort you can find the explanation of the concept from wikipedia. Actually there is so detailed pseudo code here, scroll to "Version with in-place partition" that you can convert it directly to C language and have your assignment done in about 10 minutes. |
Recent GIDBlog
Developing GUIs with wxPython (Part 2) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The