On 6/06/2014 7:58 PM, John McKown wrote:
As an aside, does anybody know why C included qsort() and no other sort algorithm? qsort() is O(n log n) in general, but is O(n^2) in degenerate cases (already sorted). I might like an hsort() to implement heap sort which is O(n log n) in all cases. But wouldn't a bsort(), bubble sort, be useful to sort a small amount of data?
Almost all of the standard C library implementations of qsort() actually use introsort http://en.wikipedia.org/wiki/Introsort, which has both an average and worse case complexity of O(n log n). I too wold like hsort() because it's a stable sort, it will never be quicker. There are heaps of excellent open source implementations out there so take your pick. I certainly see no reason why they should be written in assembler! I personally just use C++ std::sort() and std::stable_sort() which is an excellent implementation on z/OS with the Dinkumware STL (written by professor Plauger).
Would it be "worth while" to bother writing some code for CBT distribution which implements the above interface to DFSORT, and maybe even includes an hsort() and bsort()? Or is C just not the language for this sort (pun intended) of processing?
---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
