Skip to content
All tags

#generics

3 posts

Stanford CS107 Lecture 13: From Comparators to a Fully Generic Bubble Sort

CS107 Lecture 13 upgrades a Boolean callback to a three-way comparator, then combines void *, element width, and const void * callbacks into a fully generic bubble sort before mapping the design to qsort, bsearch, lfind, and lsearch.

Stanford CS107 Lecture 12: Function Pointers Inject Ordering into Generic C

CS107 Lecture 12 first uses char * for byte-wise generic swap and rotate, then uses a function pointer to separate bubble sort's traversal mechanism from its ordering rule: void * abstracts data types, while callbacks abstract behavior.

Stanford CS107 Lecture 11: How void * Gives C Generics Without Pretending Types Still Exist

CS107 Lecture 11 finishes the heap contracts of calloc, strdup, free, and realloc, then turns several typed swap functions into void * plus a byte count: C generics do not preserve an unknown type; they explicitly transfer responsibility for addresses, widths, and interpretation.