Name
mgsort
Synopsis
int mgsort(void*data
, intsize
, intesize
, inti
, intk
, int (*compare
) (const void *key1
, const void *key2
));
Return Value
0 if sorting is successful, or -1 otherwise.
Description
Uses merge sort to sort the array of elements in
data
. The number of elements in
data
is specified by
size
. The size of each element is
specified by esize
. The arguments
i
and k
define the current division being sorted and initially should be
and size
- 1, respectively. The
function pointer compare
specifies a
user-defined function to compare elements. It should perform in a
manner similar to that described for issort.
When mgsort returns,
data
contains the sorted
elements.
Complexity
O (n lg n), where n is the number of elements to be sorted.
Get Mastering Algorithms with C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.