C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
sorts.h
Go to the documentation of this file.
1/**
2 * @file sorts.h
3 * @brief Unified header for all sorting algorithms.
4 *
5 * Each comparison-based algorithm has both a string and an int variant.
6 * Radix sort is integers-only (LSD byte-by-byte counting sort).
7 *
8 * | Algorithm | Time (avg) | Time (worst) | Space | Stable |
9 * |----------------|-------------|--------------|---------|--------|
10 * | Selection sort | O(n²) | O(n²) | O(1) | No |
11 * | Bubble sort | O(n²) | O(n²) | O(1) | Yes |
12 * | Insertion sort | O(n²) | O(n²) | O(1) | Yes |
13 * | Quicksort | O(n log n) | O(n²) | O(log n)| No |
14 * | Merge sort | O(n log n) | O(n log n) | O(n) | Yes |
15 * | Heap sort | O(n log n) | O(n log n) | O(1) | No |
16 * | Radix sort | O(n × bytes)| O(n × bytes) | O(n) | Yes |
17 */
18
19#ifndef SORTS_H
20#define SORTS_H
21
22#include <stddef.h>
23
24/* ── Selection sort ─────────────────────────────────────────────────── */
25void selection_sort_strings(char **arr, size_t n);
26void selection_sort_ints(int *arr, size_t n);
27size_t find_min_index(char **arr, size_t start, size_t n);
28
29/* ── Insertion sort ─────────────────────────────────────────────────── */
30void insertion_sort_strings(char **arr, size_t n);
31void insertion_sort_ints(int *arr, size_t n);
32
33/* ── Bubble sort ────────────────────────────────────────────────────── */
34void bubble_sort_strings(char **arr, size_t n);
35void bubble_sort_ints(int *arr, size_t n);
36
37/* ── Quicksort (Lomuto partition) ───────────────────────────────────── */
38void quicksort_strings(char **arr, size_t n);
39void quicksort_ints(int *arr, size_t n);
40
41/* ── Merge sort ─────────────────────────────────────────────────────── */
42void merge_sort_strings(char **arr, size_t n);
43void merge_sort_ints(int *arr, size_t n);
44
45/* ── Heap sort ──────────────────────────────────────────────────────── */
46void heap_sort_strings(char **arr, size_t n);
47void heap_sort_ints(int *arr, size_t n);
48
49/* ── Radix sort (non-negative integers only) ───────────────────────── */
50void radix_sort_ints(int *arr, size_t n);
51
52#endif /* SORTS_H */
void quicksort_ints(int *arr, size_t n)
Definition quicksort.c:76
void selection_sort_ints(int *arr, size_t n)
size_t find_min_index(char **arr, size_t start, size_t n)
void insertion_sort_ints(int *arr, size_t n)
void insertion_sort_strings(char **arr, size_t n)
void heap_sort_ints(int *arr, size_t n)
Definition heap_sort.c:16
void merge_sort_strings(char **arr, size_t n)
Definition merge_sort.c:36
void bubble_sort_ints(int *arr, size_t n)
Definition bubble_sort.c:30
void bubble_sort_strings(char **arr, size_t n)
Definition bubble_sort.c:14
void selection_sort_strings(char **arr, size_t n)
void heap_sort_strings(char **arr, size_t n)
Definition heap_sort.c:48
void quicksort_strings(char **arr, size_t n)
Definition quicksort.c:42
void merge_sort_ints(int *arr, size_t n)
Definition merge_sort.c:66
void radix_sort_ints(int *arr, size_t n)
Definition radix_sort.c:38