libft
Loading...
Searching...
No Matches
Files | Macros | Functions
Sorting Utilities

General-purpose sorting utilities including a custom quicksort. More...

Files

file  ft_qsort.c
 Generic quicksort implementation with fallback to insertion sort.
 
file  ft_sorting.h
 Sorting utility functions and comparators.
 

Macros

#define QSORT_THRESHOLD   10
 

Functions

int double_cmp (const void *a, const void *b)
 Comparison function for two doubles.
 
void ft_qsort (void *base, size_t nmemb, size_t size, int(*cmp)(const void *, const void *))
 Sorts an array using quicksort and insertion sort fallback.
 
int int_cmp (const void *a, const void *b)
 Comparison function for two integers.
 

Detailed Description

General-purpose sorting utilities including a custom quicksort.

This group contains functions related to sorting arrays using a generic implementation of the quicksort algorithm. It also includes basic comparator functions for integers and doubles that can be passed to ft_qsort.

Macro Definition Documentation

◆ QSORT_THRESHOLD

#define QSORT_THRESHOLD   10

#include <include/ft_sorting.h>

Threshold to switch sort strategy

Function Documentation

◆ double_cmp()

int double_cmp ( const void *  a,
const void *  b 
)

#include <include/ft_sorting.h>

Comparison function for two doubles.

Compares the two doubles pointed to by a and b and returns a standard comparator result.

Parameters
aPointer to the first double.
bPointer to the second double.
Returns
Negative if a < b, 0 if equal, positive if a > b.
See also
ft_qsort

◆ ft_qsort()

void ft_qsort ( void *  base,
size_t  nmemb,
size_t  size,
int(*)(const void *, const void *)  cmp 
)

#include <include/ft_sorting.h>

Sorts an array using quicksort and insertion sort fallback.

Sorts an array of any type using a generic quicksort implementation. Falls back to insertion sort for small subarrays.

Parameters
basePointer to the first element of the array.
nmembNumber of elements in the array.
sizeSize in bytes of each element.
cmpComparison function returning:
  • Negative if a < b
  • 0 if a == b
  • Positive if a > b
See also
int_cmp
double_cmp

◆ int_cmp()

int int_cmp ( const void *  a,
const void *  b 
)

#include <include/ft_sorting.h>

Comparison function for two integers.

Compares the two integers pointed to by a and b and returns a standard comparator result.

Parameters
aPointer to the first integer.
bPointer to the second integer.
Returns
Negative if a < b, 0 if equal, positive if a > b.
See also
ft_qsort