6 ms·
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++.
by osolo 15y 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++.
- archangel_one 15y agostd::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.
- steve-howard 15y agoI believe said requirements were written to allow qsort.
- albertzeyer 15y agoThat'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/kern/qsort.c 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 http://www.umcs.maine.edu/~chaw/200801/capstone/n/qsort.c
- cygx 15y agoThe 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.