Generic quicksort library that can be used to sort an array having any data type (int, char *, struct key_value *, etc.).

Collin Funk collin.funk1@gmail.com
Sat Sep 27 04:22:52 GMT 2025


Amit <amitchoudhary0523@gmail.com> writes:

> Actually, we don't know what will be the size of the elements. It may be
> small and it may be big also.  So, sometimes the swap function will be
> better and sometimes it will not.

Programs that have to sort large amounts of data, that may exceed the
amount of memory in the system, will not rely on qsort. They will
implement external sorting on their own [1].

> So, in scenarios where no algorithm offers obvious advantages, I actually
> choose the algorithm which is simpler to implement and understand. So, I
> would still take the swap function from the user. The implementation will
> be very simple and in future if someone else takes charge of the code then
> he/she won't have to spend a lot of time to understand it.

The qsort function is well defined by the POSIX standard. Even if I
agreed with your arguments, we cannot do things like change the
arguments that it accepts.

Also, stable sorting is an advantage [2]. We moved back to merge sort
because some programs rely on qsort being stable. Lets not break
programs.

Collin

[1] https://en.wikipedia.org/wiki/External_sorting
[2] https://en.wikipedia.org/wiki/Sorting_algorithm#Stability


More information about the Libc-alpha mailing list