It is already written.
It is already debugged.
It has been optimized as much as possible (usually).
The algorithm used by qsort() is generally the quick sort algorithm, developed by C. A. R. Hoare in 1962.
Here is the prototype for qsort():
void qsort(void *buf, size_t num, size_t size,
int (*comp)(const void *ele1, const void *ele2));
The qsort() function takes a pointer to an array of user-defined data (buf). The array has num elements in it, and each element is size bytes long. Decisions about sort order are made by calling comp,