Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Recursion is stupid and wasteful

Name: Anonymous 2013-05-23 4:36

There is nothing that recursion can do that can't be done simpler and more elegantly with a plain for loop.

Name: Anonymous 2013-05-25 22:09

>>43
Do it yourself.  The non-recursive version doesn't really require any added complexity to switch off sorting methods, because checking for completion is the same as checking for small problem size, and it would be suboptimal anyway, I'm pretty sure

As a side note, the stack used in the nonrecursive version requires only one argument pushed, whereas traditional recursive qsort requires much more (instruction pointer, data, length).  If the partition() method is sufficient, the maximum depth of the stack can be calculated beforehand to remove the irritating realloc() calls (I think my version bounds it as (to-from)/2).  Also, the touted multithreading of qsort can still be used, especially since the explicit stack allows forking/threading at a predetermined arbitrary level. So the non recursive version pretty much uses better than tail-recursion for both calls, and the only overhead is moving the stack from implicit to explicit representation.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List