Templates – Generic Programming
As a computer scientist, or as a programming enthusiast, at some point in time, you probably had to write one (or more) sort algorithms. When discussing the algorithm, you were not particularly concerned about the type of data being sorted, just that the two objects of that type could be compared and that the domain is a totally ordered set (that is, if one object is compared with any other, you can determine which comes first). Different programming languages provide different solutions to this problem:
- Python: A dynamic language with built-in function sort and member functions on list. As a dynamic language, it does not need to concern itself with the type if it can call the comparison operator and a swap function.
- C: This has a function in its standard library called qsort that has the following signature:
void qsort (void* base, size_t num, size_t size, ...