Hacker News new | ask | show | jobs
by osolo 5207 days ago
Exactly. std::sort does NOT use quick sort. So all he's doing is comparing two different algorithms. It has nothing to do with C vs C++.
3 comments

That's not exactly true. `std::sort` can use quick sort. It depends on the implementation.

As well as `qsort`. It is also not guaranteed to use quick sort.

E.g., here is the BSD qsort: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd...

Here is the glibc one: http://www.umcs.maine.edu/~chaw/200801/capstone/n/qsort.c

The more relevant difference here is probably compile-time generic code which can take advantage of inlining vs run-time generic code which can't.

However, C compilers are smart enough to transform the latter into the former, but only if you let them.

std::sort isn't guaranteed to use any particular algorithm, but IIRC quicksort fits the requirements and hence has been used in the past, even if introsort might be more common now.
I believe said requirements were written to allow qsort.