DOKK / manpages / debian 13 / libsdl3-doc / SDL_qsort.3.en
SDL_qsort(3) SDL3 FUNCTIONS SDL_qsort(3)

SDL_qsort - Sort an array.

Defined in SDL3/SDL_stdinc.h

#include "SDL3/SDL.h"
void SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare);

For example:

typedef struct {

int key;
const char *string; } data; int SDLCALL compare(const void *a, const void *b) {
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
} } data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" } }; SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);

a pointer to the start of the array.
the number of elements in the array.
the size of the elements in the array.
a function used to compare elements in the array.

It is safe to call this function from any thread.

This function is available since SDL 3.2.0.

(3), SDL_bsearch(3), (3), SDL_qsort_r(3)

SDL 3.2.10 Simple Directmedia Layer