Skip to main content

Generic Library: Sort, Search, Dedup

Challenge on lesson: Checkpoint: The Generic Layer Cake

Ship the mini-library: a generic toolkit over void* with a typed facade. The boilerplate declares the raw engine and the facade macro (you implement the engine functions; the facade is given): ``c /* engine: */ void g_sort(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *)); /* any sort you like */ size_t g_dedup(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *)); /* removes adjacent duplicates (array MUST be sorted first — sort it yourself inside), returns new length. In place; tail is unspecified. */ /* facade over int arrays only: */ #define isort(a, n) g_sort((a), (n), sizeof(int), cmp_int) ` cmp_int` is provided in the boilerplate.

Difficulty: intermediate

Back to lesson: Checkpoint: The Generic Layer Cake