Name

ctsort

Synopsis

int ctsort(int *data, int size, int k);

Return Value

0 if sorting is successful, or -1 otherwise.

Description

Uses counting sort to sort the array of integers in data. The number of integers in data is specified by size. The argument k specifies the maximum integer in data, plus 1. When ctsort returns, data contains the sorted integers.

Complexity

O (n + k), where n is the number of integers to be sorted and k is the maximum integer in the unsorted set, plus 1.

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.