C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
sorts.h File Reference

Unified header for all sorting algorithms. More...

#include <stddef.h>

Go to the source code of this file.

Functions

void bubble_sort_ints (int *arr, size_t n)
 
void bubble_sort_strings (char **arr, size_t n)
 
size_t find_min_index (char **arr, size_t start, size_t n)
 
void heap_sort_ints (int *arr, size_t n)
 
void heap_sort_strings (char **arr, size_t n)
 
void insertion_sort_ints (int *arr, size_t n)
 
void insertion_sort_strings (char **arr, size_t n)
 
void merge_sort_ints (int *arr, size_t n)
 
void merge_sort_strings (char **arr, size_t n)
 
void quicksort_ints (int *arr, size_t n)
 
void quicksort_strings (char **arr, size_t n)
 
void radix_sort_ints (int *arr, size_t n)
 
void selection_sort_ints (int *arr, size_t n)
 
void selection_sort_strings (char **arr, size_t n)
 

Detailed Description

Unified header for all sorting algorithms.

Each comparison-based algorithm has both a string and an int variant. Radix sort is integers-only (LSD byte-by-byte counting sort).

Algorithm Time (avg) Time (worst) Space Stable
Selection sort O(n²) O(n²) O(1) No
Bubble sort O(n²) O(n²) O(1) Yes
Insertion sort O(n²) O(n²) O(1) Yes
Quicksort O(n log n) O(n²) O(log n) No
Merge sort O(n log n) O(n log n) O(n) Yes
Heap sort O(n log n) O(n log n) O(1) No
Radix sort O(n × bytes) O(n × bytes) O(n) Yes

Definition in file sorts.h.

Function Documentation

◆ bubble_sort_ints()

void bubble_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 30 of file bubble_sort.c.

◆ bubble_sort_strings()

void bubble_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 14 of file bubble_sort.c.

Referenced by algo_from_name().

◆ find_min_index()

size_t find_min_index ( char **  arr,
size_t  start,
size_t  n 
)

Definition at line 12 of file selection_sort.c.

Referenced by selection_sort_strings().

◆ heap_sort_ints()

void heap_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 16 of file heap_sort.c.

References heap_sift_down_max().

◆ heap_sort_strings()

void heap_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 48 of file heap_sort.c.

References sift_down_max_str().

Referenced by algo_from_name().

◆ insertion_sort_ints()

void insertion_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 25 of file insertion_sort.c.

Referenced by main().

◆ insertion_sort_strings()

void insertion_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 12 of file insertion_sort.c.

Referenced by algo_from_name().

◆ merge_sort_ints()

void merge_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 66 of file merge_sort.c.

References merge_sort_int_recursive().

◆ merge_sort_strings()

void merge_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 36 of file merge_sort.c.

References merge_sort_str_recursive().

Referenced by algo_from_name().

◆ quicksort_ints()

void quicksort_ints ( int *  arr,
size_t  n 
)

Definition at line 76 of file quicksort.c.

References quicksort_int_recursive().

◆ quicksort_strings()

void quicksort_strings ( char **  arr,
size_t  n 
)

Definition at line 42 of file quicksort.c.

References quicksort_str_recursive().

Referenced by algo_from_name().

◆ radix_sort_ints()

void radix_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 38 of file radix_sort.c.

References counting_pass().

◆ selection_sort_ints()

void selection_sort_ints ( int *  arr,
size_t  n 
)

Definition at line 41 of file selection_sort.c.

◆ selection_sort_strings()

void selection_sort_strings ( char **  arr,
size_t  n 
)

Definition at line 24 of file selection_sort.c.

References find_min_index().

Referenced by algo_from_name(), and main().