## Sorting

#include <iostream>#include <ranges>#include <vector>#include <list>#include <algorithm>#include <random>#include <iterator> int main() { const auto printy = [](const auto& v) { std::cout << "\n"; std::ranges::copy(v, std::ostream_iterator<int>(std::cout, ",\n")); }; // Make container of random values std::vector<int> v(4); std::ranges::for_each(v, [](auto &x){ x = std::rand(); }); printy(v); // Sort it std::ranges::sort(v); printy(v); // Sort it the other way std::ranges::sort(v, std::greater<int>()); printy(v); // List has its own sort std::list<int> l{std::cbegin(v), std::cend(v)}; l.sort(); printy(l); } https://godbolt. [Read More]

## Algorithms

The conventional wisdom for when to use a linked list over contiguous storage hasn’t applied for years: you have to test. If everything is in a cache, a vector might outperform a linked list for insertion. Sorting See post/sort. GB CppCon 2018: Jonathan Boccara – 105 STL Algorithms in Less Than an Hour https://www.youtube.com/watch?v=2olsGf6JIkU Secret runes stable_ is_ is_*_until Algorithm patterns Brute Force Divide and Conquer Karatsuba’s Integer Multiplication – it is possible to perform multiplication of large numbers in (many) fewer operations than the usual brute-force technique of “long multiplication. [Read More]