Re: qsort and arbitrary types
From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 06/11/04
- Previous message: Hans-Bernhard Broeker: "Re: Subroutine Argument Checking"
- In reply to: David Frank: "Re: qsort and arbitrary types"
- Next in thread: David Frank: "Re: qsort and arbitrary types"
- Reply: David Frank: "Re: qsort and arbitrary types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 00:47:27 GMT
David Frank wrote:
> quicksort algorithm is short enuf to duplicate it into a generic
> solution.. ie:
That's what I said yesterday. Of course, I'd have written
a standard conforming code for the sort. And, I'd have written
an efficient version that was not recursive and made no redundant
compares during the partitioning. And, as I said, the code that
all versions shared would be in an include file, rather than
writing it separately several times. Also, why you used a module
to contain the generic interface, but not the code is incomprehensible:
it just makes the interface block more verbose and harder to read.
And, the procedure needs only one argument rather than three:
the array itself (you can pass a slice which will contain its own
bounds, assuming you insist on leaving the code recursive).
And, why you maintained you indices as if the arrays were
zero-based and then always had to add one back to make them
legitimate indices again is also incomprehensible. And, the stack
requirement of your version is potentially one less than the size
of the argument array - an amount that may terminate the program
if the array to be sorted already requires a lot of memory. Quicksort
can be written to use a stack of, at most, the log (base 2) of the
size of the array. And, qsort is not particularly efficient for small
partitions. Other optimizations are also applicable.
I guess I was wrong when I said that we all knew quicksort
well enough that I didn't have to go into its details.
-- J. Giles
- Previous message: Hans-Bernhard Broeker: "Re: Subroutine Argument Checking"
- In reply to: David Frank: "Re: qsort and arbitrary types"
- Next in thread: David Frank: "Re: qsort and arbitrary types"
- Reply: David Frank: "Re: qsort and arbitrary types"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|