Module 12 · sort, Comparators and Lambdas: Tell the Algorithm What You Mean
Full Programs: From a Race Table to a priority_queue That Takes Your Rule
Free with an accountReading
A working programmer rarely sorts plain numbers. She sorts words by length, riders by points, runners by time and books by author. Each job is the same sort call with a different rule, the comparator that answers "must a come before b?". Six programs follow, each a little bigger than the last. Read the "new thing" line above each program first; it is what that program is for.
Checking what this lesson needs for you…
What is inside Full Programs: From a Race Table to a priority_queue That Takes Your Rule
- Program 1: words by length, then from a to z
- Program 2: a race table with std::tie, one key high to low
- Program 3: sort the indices, not the values
- Program 4: sort, then walk the equal runs
- Program 5: a priority_queue that takes your lambdaIntermediate
- Program 6: records from input, a library catalogueIntermediate