Name

issort

Synopsis

                     int issort(void *data, int size, int esize, int (*compare)(const void *key1, 
   const void *key2));

Return Value

0 if sorting is successful, or -1 otherwise.

Description

Uses insertion 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 function pointer compare specifies a user-defined function to compare elements. This function should return 1 if key1 > key2, if key1 = key2, and -1 if key1 < key2 for an ascending sort. For a descending sort, compare should reverse the cases returning 1 and -1. When issort returns, data contains the sorted elements.

Complexity

O (n 2), 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.